Reading a structured binary file?

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Aug 5 23:04:58 PDT 2013


On Tue, Aug 06, 2013 at 06:48:12AM +0200, Jesse Phillips wrote:
[...]
> The only way I'm seeing to advance through the file is to keep an
> index on where you're currently reading from. This actually works
> perfect for the FileRange I mentioned in the previous post. Though
> I'm not familiar with how mmfile manages its memory, but hopefully
> there isn't buffer reuse or storing the slice could be overridden
> (not an issue for value data, but string data).

I don't know about D's Mmfile, but AFAIK, it maps directly to the OS
mmap(), which basically maps a portion of your program's address space
to the data on the disk. Meaning that the memory is managed by the OS,
and addresses will not change from under you.

In the underlying physical memory, pages may get swapped out and reused,
but this is invisible to your program, since referencing them will cause
the OS to swap the pages back in, so you'll never end up with invalid
pointers. The worst that could happen is the I/O performance hit
associated with swapping. Such is the utility of virtual memory.


T

-- 
Error: Keyboard not attached. Press F1 to continue. -- Yoon Ha Lee, CONLANG


More information about the Digitalmars-d-learn mailing list