开发者

Fastest way to get a part of a disk file into a particular (pre-allocated) memory address Windows/C++?

Howdo.

I'm working in native Windows. That said I'm looking to write a function whose prototype is something like:

void getData(uint8_t* p, std::string const& fn, size_t off, 
    size_t s, boost::funct开发者_运维百科ion<void()> const& F);

So I've a chunk of memory, preallocated on the heap (with new). I have a file on disk. I'd like to specify a pointer into my chunk of memory ("p"), a filename ("fn") and offset therein ("off"), a size ("s") and a callback ("F"). I'd like the subroutine to eventually call "F" when my memory "p" has been populated with "s" bytes from the file "fn" at offset "off". I will guarantee "p", "s" and "off" are aligned to some predefined power of 2, but I'd like no copying that can possibly be avoided to occur. Ideally, it would DMA the data from the disk to my location directly.

I've looked into memory-mapping the file, but that would require copying the data from the mapped area into my "p". Is there no faster way of doing it?


Why not just use memory mapping with MapViewOfFileEx?

You can use p as the lpBaseAddress parameter to map the file wherever you want to in your process's address space.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜