I am trying to find a way to allocate memory dynamically for memory mapped files that are shared between different processes. My design is as follows: In Windows mobile, I am writing a Display Thread that handles the display part from different processes using shared memory. The plan is to create a memory mapped file that is equal to the size of the screen For eg: if the screen size is 640 X 480, then I create a BYTE array of 640 X 480 X 4 and then share this with another process so that the other process updates the in memory hDC display and then sends an update to the Display Thread to update the display on the device.
This works fine but one constraint is to allocate the memory at compile time as we cannot allocate the memory dynamically
(http://msdn.microsoft.com/en-us/library/aa366542%28v=vs.85%29.aspx). When you do not want the size of the file to change (for example, when mapping read-only files), call CreateFileMapping and specify zero for both dwMaximumSizeHigh and dwMaximumSizeLow. Doing this creates a file mapping object that is exactly the same size as the file. Otherwise, you must calculate or estimate the size of the finished file because file mapping objects are static in size; once created, their size cannot be increased or decreased.
- Is there a way to allocate the size of the memory mapped file after getting the device screen co-ordinates? One thing is to cater this for different screen sized devices like tablets, mobile devices etc. and another thing is that if an application wants to display only a part of the screen then we should be able to create the memory map with only that size.
- Is there any other alternative to memory mapped files? The reason why I chose Memory mapped files is that when the other process modifies the display, it need not send all the update details and can simply set a mutex to let Display thread know that it needs to refresh the screen. This way I could get a refresh rate of 50 frames per second with display from 5 different applications.
Thanks in advance
Don’t use a file, there’s no value in having this data written to disk. Pass INVALID_HANDLE_VALUE to CreateFileMapping so that the memory is backed by the paging file and you can set any size you need.