Hi,
My Scenario:
I am using File Mapping to map a very small structure across a number of processes
the structure is less then 4k (because of how windows handles memory it still ends up allocating 4k)
Code as follows:
CreateFileMapping(INVALID_HANDLE_VALUE, &securityattributes, PAGE_READWRITE, 0, sizeof(mystructure), myname);
MapViewOfFile(myhandle, FILE_MAP_READ, 0, 0, 0);
My problem:
This usually works fine, no problems at all but sometimes MapViewOfFile fails with ERROR_NOT_ENOUGH_MEMORY
My question is, On what conditions will MapViewOfFile fail with ERROR_NOT_ENOUGH_MEMORY ? (I eliminated the possibility of memory fragmentation because of the small size of my structure)
Any Ideas? Thanks !!
Thanks, MJ 
For a small, fixed-size structure, you could use a shared memory segment.
joe
Hi,
My Scenario:
I am using File Mapping to map a very small structure across a number of
processes
the structure is less then 4k (because of how windows handles memory it
still ends up allocating 4k)
Code as follows:
CreateFileMapping(INVALID_HANDLE_VALUE, &securityattributes,
PAGE_READWRITE, 0, sizeof(mystructure), myname);
MapViewOfFile(myhandle, FILE_MAP_READ, 0, 0, 0);
My problem:
This usually works fine, no problems at all but sometimes MapViewOfFile
fails with ERROR_NOT_ENOUGH_MEMORY
My question is, On what conditions will MapViewOfFile fail with
ERROR_NOT_ENOUGH_MEMORY ? (I eliminated the possibility of memory
fragmentation because of the small size of my structure)
Any Ideas? Thanks !!
Thanks, MJ 
NTDEV is sponsored by OSR
Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
OSR is HIRING!! See http://www.osr.com/careers
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
Usually it means that there is no room in the virtual address space for the
mapping. Even though you’re only asking for 4K, there is a larger virtual
alignment requirement imposed by the Memory Manager (see the MapViewOfFileEx
docs).
There are several ways to dump the virtual address space in your process to
determine if this is the cause:
- VMMap from Sysinternals
- !vad from a kernel debug session
- !address from a user debug session
-scott
OSR
@OSRDrivers
wrote in message news:xxxxx@ntdev…
Hi,
My Scenario:
I am using File Mapping to map a very small structure across a number of
processes
the structure is less then 4k (because of how windows handles memory it
still ends up allocating 4k)
Code as follows:
CreateFileMapping(INVALID_HANDLE_VALUE, &securityattributes, PAGE_READWRITE,
0, sizeof(mystructure), myname);
MapViewOfFile(myhandle, FILE_MAP_READ, 0, 0, 0);
My problem:
This usually works fine, no problems at all but sometimes MapViewOfFile
fails with ERROR_NOT_ENOUGH_MEMORY
My question is, On what conditions will MapViewOfFile fail with
ERROR_NOT_ENOUGH_MEMORY ? (I eliminated the possibility of memory
fragmentation because of the small size of my structure)
Any Ideas? Thanks !!
Thanks, MJ 
Is it a plain Win8 install without app verifier and Driver verifier enabled?
How often do you create the file mapping and map it?
Will shared memory segments work across different processes? (this library is loaded by a number of different modules which can be running under different processes)
I did not manage to reproduce the issue in my lab yet (will using the verifier applications help with reproducing it?)
The issue is being reproduced successfully on a Windows Server 2008 machine (do not have direct access to this machine)
The mapping is called at least once every 5 minutes after about 4 days it gives error 8, (the structure that being mapped contains a single DWORD)
I did not release the memory may still get fragmented, Thanks!
Once you called MapViewOfFile, you nave to either 1) keep using that view, or 2) call UnmapViewOfFile.
It could be that the machine in question is reserving 2MB of VA per each mapping. What mapping addresses do you see?
The number of mappings you observe would then exaust the address space of a 32 bit process. Unless you play fair and unmap the view before mapping it again (or don’t try to remap it).
> Will shared memory segments work across different processes? (this library is loaded by a number
of different modules which can be running under different processes)
Yes.
–
Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com
Note that shared memory segments are isolated within a login session. Also, they require that the DLL is always loaded by identicall full path name.
This is yet another illustration among hundreds of others of why signing our drivers is so much more than “just” coming up with the money. If it was as easy as some claim there wouldn’t be so many questions and debate over it on forums on a regular basis. Signing drivers hurts developer productivity which is a negative to our companies and our customers. Most consumers see driver signing popups as just an obstacle between them and doing what they want and click through it to get rid of it just like closing a pop up advertisement. If there is one class of users we needed to protect, it’s them so it’s failed. And maybe if not for this mess of driver signing issues we deal with over and over maybe we would still have a useful discussion about threads here.
On Apr 16, 2014, at 5:29 PM, xxxxx@gmail.com wrote:
This is yet another illustration among hundreds of others of why signing our drivers is so much more than “just” coming up with the money. If it was as easy as some claim there wouldn’t be so many questions and debate over it on forums on a regular basis. Signing drivers hurts developer productivity which is a negative to our companies and our customers.
Oh, come on. In the Win 8.x WDKs, driver signing is just a checkbox, and adds about 4 seconds to every build. The impact to developer productivity is negligible.
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
Even in older WDKs this process is set up once and can be included to the build script.
“Tim Roberts” wrote in message news:xxxxx@ntdev…
On Apr 16, 2014, at 5:29 PM, xxxxx@gmail.com wrote:
> This is yet another illustration among hundreds of others of why signing our drivers is so much more than “just” coming up with the money. If it was as easy as some claim there wouldn’t be so many questions and debate over it on forums on a regular basis. Signing drivers hurts developer productivity which is a negative to our companies and our customers.
Oh, come on. In the Win 8.x WDKs, driver signing is just a checkbox, and adds about 4 seconds to every build. The impact to developer productivity is negligible.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.