elast0ny / shared_memory

A Rust wrapper around native shared memory for Linux and Windows
382 stars 51 forks source link

Resizing memory #31

Closed jefshe closed 5 years ago

jefshe commented 5 years ago

Hi, I'm using this library to allocate a portion of shared memory where data may differ wildly in size. Does the library have any mechanism for resizing previously allocated shared memory?

elast0ny commented 5 years ago

Hi,

I've thought about this before and seem to remember that some OSes (Windows I believe) did not support resizing of mapped memory.

In addition, once the shared memory has been initialized and is in use by multiple processes, any changes to the shared memory itself need to be done synchronously which is outside the scope of this crate. This issue is more problematic when you're shrinking the mapping and some parts become invalid (all processes using the shmem need to be aware). Processes that are opening the mapping and reading the metadata (which is currently static) would also have to respect some locking mechanism as the metadata might be changing as the mapping is being resized...

Not impossible but I think this functionality could be wrapped in a "shmem allocator" style crate which does all the synchronization and creation of multiple mappings on the fly.

jefshe commented 5 years ago

fair point, it seems like it would be a lot of work to tack onto this crate and even more so if it's not cross platform.

I'll close this issue then

asajeffrey commented 5 years ago

Advert: the shared-data crate should eventually handle memory allocation/deallocation.