Shashi Subbarao

I have a program that creates memory mapped files (shared memory) and are not mapped to a file directly. When I try to allocate a bunch of memory mapped files, it works fine with 128MB and 256MB chunks but fails with 512MB and 1GB chunks. CreateFileMapping succeeds but MapViewofFile fails with GetLastError 8 (ERROR_NOT_ENOUGH_MEMORY). This is on a Windows 2003 server 32-bit edition SP1 with 4GB ram and the page file size is set to 'System managed'.

Any ideas as to why allocation of say, five 256MB memory mapped files works fine but allocation of one 1GB memory mapped file fails with ERROR_NOT_ENOUGH_MEMORY

Thanks in advance,

Shashi.



Re: Visual C++ Language Memory mapped file size limit

Simple Samples

This is not a VC Language question; it is a Windows question that should be asked in a Windows newsgroup or a forum in a programming site in which this is within the scope of the forum.

My guess is that it would be quite difficult for Windows to obtain 1 GB of contiguous memory, even for virtual storage. It is probably just not possible, regardlous of available resources. I think there is a way to get an additional 2 GB of memory space for a total of 6 GB but if so then that is an option that is not provided by default, at least not for client versions of XP and before.






Re: Visual C++ Language Memory mapped file size limit

Holger Grund

This is related to memory model of Win32. Win32 uses a simple flat 32-bit memory layout. That means each process has 32-bit of addressable memory space. The upper 2GB (or 1GB with /3G switch on some later Windows SKUs and PE images marked with the appropriate flag) are reserved to the system. So you only have a 2GB of virtual address space and all kinds of things competing for it:

  • EXE/DLL modules
  • Stack (default is 1MB per thread)
  • Heap
  • Shared memory/memory mapped files
  • ...

Therefore, you cannot easily get a contigious range of address space. As you see address space and not physical RAM is the problem here. It is probably a bad thing to allocate such a huge chunk, but if you have to then you should do so very early in the process.

-hg





Re: Visual C++ Language Memory mapped file size limit

Shashi Subbarao

I apologize for posting the question here. I found the answer to my question that allocating 128MB or 256MB works but 512MB or 1GB on Windows 2003 server 32bit edition fails because of the following : 2GB VM limit per process as well as 470MB paged pool limit and 256MB non-paged pool limit per process. I also found that using the /3GB switch doesn't help.

Thanks for your replies.

Shashi.





Re: Visual C++ Language Memory mapped file size limit

Jim Monte

FYI, I was able create a maping for an entire 6 GB file and map just under the first 2 GB of it running NT 4 SP 6. Attempting to map more gave an assortmemt of errors depending on how much was specified. Don't worry about physical memory size. The machine I was using has only 128 MB of RAM.

Jim





Re: Visual C++ Language Memory mapped file size limit

Simple Samples

Good. So my guess was wrong.

I did not intend to mislead you, but hopefully the SDK newsgroup would have been more helpful.






Re: Visual C++ Language Memory mapped file size limit

Simple Samples

Oooops, I now see that the post I am replying to was not posted by the person asking the question.




Re: Visual C++ Language Memory mapped file size limit

Brian Kramer

Please reserve use of this forum for C++ language issues. For question such as this one, the Win32 kernel newsgroup is an apt place to go: http://msdn.microsoft.com/newsgroups/default.aspx dg=microsoft.public.win32.programmer.kernel&lang=en&cr=US

Thanks.

OTP