Archived

This topic is now archived and is closed to further replies.

File mapping

This topic is 5306 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I am working at the moment on an archiv system. Everything works perfectly. Now I want to get some speed. So i thing file mapping would give me this boost. But I have some questions: 1. Is is good to map 130 MB files? 2. Or should i only map the compressed files in the archiv, if they needed? 3. Is there a benchmark or something like that? fopen vs file mapping. Thanks, Christian

Share this post


Link to post
Share on other sites
Why do you think file mapping will give you a speed boost? Have you profiled yet? Where is the bottleneck in your datapath?


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
No i havent profiled it yet, because i havent wrote the file mapping part.

I have found this reasons for file mapping:
Speed is one of them. Reading a file via memory-mapping can easily outperform traditional buffered i/o methods. The reasons:
1) Memory-mapped files do no copying internally. Typically with buffered i/o data is read from disk into a buffer, then copied into another buffer when the application calls read(). Memory mapped files skip this step by reading the data directly into the area of memory that you access it from.
2) Memory mapped files work in page sized chunks of data. On Intel machines this means the fundamental unit is 4KB. Plus you can give the memory-mapped file API hints as to how you use the file (sequentially or random access) to optimize how it reads the data.
3) Memory mapped files use the same code in the kernel as page-swapping for virtual memory. This code is tightly optimized because the whole OS depends on it (while I''m sure buffered I/O is also tightly optimized, the extra copies and memory allocation still slow it down).

Share this post


Link to post
Share on other sites
Cool - Now my last question, i hope

I have this struct:
struct x
{
unsigned int a;
unsigned int b;
unsigned int c;
float d
char* f
};

The struct is at the first position of the mapped file.
Now i make x MyStruct;
MyStruct = some Code

Can somebody tell me, how i make that. How i can load the data of the mapped file into the struct.

Share this post


Link to post
Share on other sites