Implements storage for memory that can be shared between threads. More...
Public Member Functions
|shared_memory (int size, const char *identity)|
|a shared chunk of the "size" specified will be created. |
|cleans up the shared bit of memory as far as we're concerned. |
|bool||valid () const|
|this must be true for the shared_memory to be usable. |
|int||size () const|
|returns the size of the shared chunk of memory. |
|const basis::astring &||identity () const|
|provides a peek at the name that this chunk was constructed with. |
|bool||first_usage (basis::abyte *locked_memory, int max_compare)|
|returns true if the "locked_memory" was just created. |
|basis::abyte *||lock ()|
|locks the shared memory and returns a pointer to the storage. |
|void||unlock (basis::abyte *&to_unlock)|
|returns control of the shared memory so others can access it. |
Static Public Member Functions
|static basis::astring||unique_shared_mem_identifier (int sequencer)|
|returns a unique identifier for a shared memory chunk. |
Implements storage for memory that can be shared between threads.
Provides a means to create shared memory chunks and access them from anywhere in a program or from cooperating programs.
|const char *||identity|
a shared chunk of the "size" specified will be created.
it is named by the "identity" string. that "identity" uniquely points to one shared chunk on this machine. note that if this object is the first to create the chunk of memory, then all of the contents are initialized to zero. this can be used to determine if the chunk needs higher level, application-specific initialization.
|bool application::shared_memory::first_usage||(||basis::abyte *||locked_memory,|
returns true if the "locked_memory" was just created.
that is assuming that a user of the shared memory will set the first "max_compare" bytes to something other than all zeros. this is really just a test of whether bytes zero through bytes "max_compare" - 1 are currently zero, causing a return of true. seeing anything besides zero causes a false return.
|const astring & application::shared_memory::identity||(||)||const|
|abyte * application::shared_memory::lock||(||)|
locks the shared memory and returns a pointer to the storage.
the synchronization supported is only within this program; this type of shared memory is not intended for access from multiple processes, just for access from multiple threads in the same app.
|int application::shared_memory::size||(||)|| const
returns a unique identifier for a shared memory chunk.
the id returned is unique on this host for this particular process and application, given a "sequencer" number that is up to the application to keep track of uniquely. the values from -100 through -1 are reserved for hoople library internals.
|void application::shared_memory::unlock||(||basis::abyte *&||to_unlock||)|
|bool application::shared_memory::valid||(||)|| const