Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows: Resize shared memory

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.

like image 929
mooware Avatar asked Jun 06 '11 15:06

mooware


People also ask

How do I remove shared memory in Windows 10?

Advanced > Video Configuration Menu > Onboard Video Memory Size Here you can modify or even disable shared memory.

What is shared memory and when will you use it?

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.

How do I create a shared memory in Windows?

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.


1 Answers

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.

like image 196
Bukes Avatar answered Sep 19 '22 11:09

Bukes