Module shadow_shmem::allocator
source · Expand description
In this module is a shared memory allocator that can be used in Shadow to share data between the main simulator process and managed processes. There are three main global functions that are provided:
(1) shmalloc()
, which places the input argument into shared memory and returns a Block
smart pointer.
(2) shfree()
, which is used to deallocate allocated blocks.
(3) shdeserialize()
, which is used to take a serialized block and convert it back into a
Block
smart pointer that can be dereferenced.
Blocks can be serialized with the .serialize()
member function, which converts the block to a
process-memory-layout agnostic representation of the block. The serialized block can be
one-to-one converted to and from a string for passing in between different processes.
The intended workflow is:
(a) The main Shadow simulator process allocates a shared memory block containing an object. (b) The block is serialized. (c) The serialized block is turned into a string. (d) The string is passed to one of Shadow’s child, managed processes. (e) The managed process converts the string back to a serialized block. (f) The serialized block is deserialized into a shared memory block alias. (g) The alias is dereferenced and the shared object is retrieved.
Structs§
- A smart pointer class that holds a
Sync
andVirtualAddressSpaceIndependent
object. - This struct is analogous to the
ShMemBlock
smart pointer, except it does not assume ownership of the underlying memory and thus does not free the memory when dropped. - Safe wrapper around our low-level, unsafe, nostd shared memory allocator.
- The intended singleton destructor for the global singleton shared memory allocator.
Functions§
- This function takes a serialized block and converts it back into a BlockAlias that can be dereferenced.
- This function frees a previously allocated block.
- This function moves the input parameter into a newly-allocated shared memory block. Analogous to
malloc()
.