473,486 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

MapViewOfFile...

Hi !
I have a problem with the MapViewOfFile API.
I use this API to store data in files in my own database system management ;
when I need to store new data, is the file is NOT large enought, I close the
file, reopen and grow it (CreateFileMapping) and re-call MapViewOfFile (last
argument is 0, so I map entire file) ; sometimes, it returns NULL and
GetLastError returns 8 (not enought space). I test it with differents
computers, with 512 Mb RAM to 2Gb RAM, with large swap files, but the
problem seems not to be linked to memory... More over, the memory occupied
by my application is always less that physical memory...
It seems to happen when file is about 250 Gb, but it's not systematic...
More over, it seems to have differents behaviours between Win2000 and WinXP.
Is this a problem due to memory fragmentation ?
Thanks for any help...

Emmanuel Derriey
Nov 16 '05 #1
2 5861
Emmanuel Derriey wrote:
I have a problem with the MapViewOfFile API.
I use this API to store data in files in my own database system
management ; when I need to store new data, is the file is NOT large
enought, I close the file, reopen and grow it (CreateFileMapping) and
re-call MapViewOfFile (last argument is 0, so I map entire file) ;
sometimes, it returns NULL and GetLastError returns 8 (not enought
space).


You already got the answer, didn´t you ?

The problem is that if you want to map the whole file, there must be an
continous range of virtual address to map the file. For many reasons
there is no virtual address range with the desired length in your apps
address space.

Maybe the low fragmentation heap can help you:

Low-fragmentation Heap
http://msdn.microsoft.com/library/en-
us/memory/base/low_fragmentation_heap.asp

The Windows XP Low Fragmentation Heap Algorithm Feature Is Available for
Windows 2000
http://support.microsoft.com/?kbid=816542
You also should try to split the file mapping, so you do not need to map
the whole file. This can be easily done by a wrapper class for the file
mapping. Access the file mapping with this class. Internally you can map
the needed portion of the file if it is not yet mapped.

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/useritems/leakfinder.asp
Nov 16 '05 #2
Emmanuel Derriey wrote:
I have a problem with the MapViewOfFile API.
I use this API to store data in files in my own database system
management ; when I need to store new data, is the file is NOT large
enought, I close the file, reopen and grow it (CreateFileMapping) and
re-call MapViewOfFile (last argument is 0, so I map entire file) ;
sometimes, it returns NULL and GetLastError returns 8 (not enought
space).


Could you please give more details (possibly a code excerpt) about the
exact sequence of operations that take place when you decide to destroy
the current file mapping and create a larger one?

Also, look at the documentation of CreateFileMapping:

dwMaximumSizeLow
[in] Low-order DWORD of the maximum size of the file mapping object. If
this parameter and dwMaximumSizeHigh are zero, ***the maximum size of
the file mapping object is equal to the current size of the file
identified by hFile***.

So, if you need to have a MMF larger than the mapped file, you must
explicitly set the size of the MMF (GetFileSize + extra bytes).

--
Patrick Philippot - Microsoft MVP [.Net]
MainSoft Consulting Services
www.mainsoft.xx
(replace .xx with .fr when replying by e-mail)
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7580
by: Srijit Kumar Bhadra | last post by:
Hello, Here are code snippets to create and access shared memory in Python with and without ctypes module. With regards, Srijit Filename : SharedMemCreate.py import msvcrt, mmap
0
4347
by: Srijit Kumar Bhadra | last post by:
Hello, Here is some sample code with pywin32 build 203 and ctypes 0.9.6. Best regards, /Srijit File: SharedMemCreate_Mutex_win32all.py # This application should be used with...
5
2139
by: bradtm | last post by:
I get the error: 'The specified procedure could not be found.' Anyone know why? I get the error to the call of the function MapViewOfFile(): Private Const FILE_MAP_ALL_ACCESS As Integer = &H1...
2
2050
by: Vlad | last post by:
I'll do a mappig of a big file using a paging for reader it. The first time I call CreateFileMapping and MapViewOfFile with a page of 655360, the pointer is not null; then I want to read another...
8
564
by: Dave | last post by:
I am serialising an object to a memory mapped file (using the CreateFileMapping and MapViewOfFile p/invoke calls). These need to know the maximum size of the "file". I can put in a "good guess" ie...
4
2117
by: Lloyd Dupont | last post by:
I need to access big data in a readonly fashion. I was thinking to open a FileStream and seek and read as needed. I was wondering if it was worth doing my own FileStream class which would use...
25
3354
by: marcin.rzeznicki | last post by:
Hello everyone I've got a little problem with choosing the best decoding strategy for some nasty problem. I have to deal with very large files wich contain text encoded with various encodings....
5
5258
by: Tim | last post by:
Hello Everyone, I am getting shared memory in python using the following. szName = c_char_p(name) hMapObject = windll.kernel32.CreateFileMappingA(INVALID_HANDLE_VALUE, None, PAGE_READONLY, 0,...
5
3773
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
0
7094
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6839
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7305
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5427
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.