File mapping

Started by
6 comments, last by Austrian Coder 20 years, 10 months ago
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
Advertisement
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.
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).
File-mapping is a good solution for this problem given that you know the upperbound of file size.

Kuphryn
So can anybody tell me, if it is clever to map a very big file (150 - 500 MB)?
Yes. The OS will handle this appropriatly
Given that SQL Server is implemented using File Mapping, what do you think?
daerid@gmail.com
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.

This topic is closed to new replies.

Advertisement