hi all,

could someone explain in poor words the advantages of these "memmappedfiles" ?
Till now i've never used them. On a little address book i wrote i load data file in memory, update it in memory and then i re-save it as a file.
Could be better in this case use a m.m.f ?

Thanks B7
Posted on 2002-01-13 13:16:50 by Bit7
It reduces the memory requirements of your program, and uses code and memory that has already been set aside to stream the file to/from memory. Your code isn't limited to the amount of memory that is free.
Posted on 2002-01-13 14:02:22 by bitRAKE
Correct me if I'm wrong, but if I remember well, your memory mapped file can not grow up. It has to stay the same size (can be annoying for an address book).

According to Iczelion's Memory Mapped Files tutorial :
There are some limitation to file mapping though. Once you create a memory mapped file, its size cannot be changed during that session. So file mapping is great for read-only files or file operations that don't affect the file size. That doesn't mean that you cannot use file mapping if you want to increase the file size. You can estimate the new size and create the memory mapped file based on the new size and the file will grow to that size. It's just inconvenient, that's all.
Posted on 2002-01-14 01:09:42 by JCP

Your code isn't limited to the amount of memory that is free.

Well, it's sure limited to the address space size. At least if you
try mapping entire files that are large ;).

As readiosys says, you can't easily grow mmapped files. They're
most useful when you just need to read/write without expanding.
Or if you need to share data across processes (named mmap'd files).
Posted on 2002-01-14 05:41:06 by f0dder
unless i'm very much mistaken you can use SetEndOfFile
to change the size of a mem-mapped file but it was very
complicated... but in my opinion this only works if you
allocate enough memory (newsize = filesize + buffer)...
Posted on 2002-01-14 05:50:02 by mob
If you use SetEndOfFile, you probably have to re-map the file.
If you specify a filesize when creating the mapping, the file grows
to that size immediately.

Posted on 2002-01-14 05:56:05 by f0dder
How about if you know that your file would not be more that Lets Say 128 bytes. So when you write file at all time simply have blank spaces to always be available for filling up.... Strlen that amount of space or what ever...

Posted on 2002-01-14 06:12:42 by cmax
example adr-book:

you don't know how many entries the user want to
add so you allocate the old-file size of the data-base +
a huge buffer to assure enough mem available...
when the user adds a couple of entries and saves your
prog can easily calculate the amount of bytes claimed
by the new entries and use SetEndOfFile to set the
NEW end of the memory-mapped file, you can't just
close the mapping coz the db would grow very very
VERY fast... btw, I wouldn't use this technique, too but
i know, it would work fine, ok?
Posted on 2002-01-14 06:36:00 by mob
Thanks to all.
Now is more clear.

Seems them don't have a big sense for my address book or for an archive where i add records.
In any case, since there is a tut from Iczelion's i will read it.

Posted on 2002-01-14 15:27:41 by Bit7