When I create a shared memory segment on Windows (like CreateFileMapping(INVALID_HANDLE_VALUE, ...)
), is there any way to resize it, other than creating a bigger segment and copying the data?
I've read in MSDN that file mappings have a fixed size, but is there possibly some way to make a new mapping over the same memory? Like in Linux, where you can use shm_open()
and then ftruncate()
and mmap()
it again.
Advanced > Video Configuration Menu > Onboard Video Memory Size Here you can modify or even disable shared memory.
In computer science, shared memory is memory that may be simultaneously accessed by multiple programs with an intent to provide communication among them or avoid redundant copies. Shared memory is an efficient means of passing data between programs.
File mapping can be used to share a file or memory between two or more processes. To share a file or memory, all of the processes must use the name or the handle of the same file mapping object. To share a file, the first process creates or opens a file by using the CreateFile function.
The short answer is no - you cannot resize a file mapping once it has been created. The create/copy sequence you describe is the only way I'm aware of to accomplish this with file mappings backed by the system paging file.
That said, you can manage the file backing your mapping yourself and accomplish this. Start with your own zero-initialized data file, and specify valid handles to it to your calls to CreateFileMapping()
.
When you need to resize, close your mappings, extend the file, and recreate your mappings. This would require some synchronization between growth/truncating operations - not trivial, but shouldn't be too difficult either.
In the end, it's the same old story. Added complexity vs performance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With