#include <shared_memory.h>
Inheritance diagram for shared_memory:


Public Member Functions | |
| shared_memory (int size, const char *identity) | |
| a shared chunk of the "size" specified will be created. | |
| virtual | ~shared_memory () |
| cleans up the shared bit of memory as far as we're concerned. | |
| IMPLEMENT_CLASS_NAME ("shared_memory") | |
| 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 istring & | identity () const |
| provides a peek at the name that this chunk was constructed with. | |
| bool | first_usage (byte *locked_memory, int max_compare) |
| returns true if the "locked_memory" was just created. | |
| byte * | lock () |
| locks the shared memory and returns a pointer to the storage. | |
| void | unlock (byte *&to_unlock) |
| returns control of the shared memory so others can access it. | |
Static Public Member Functions | |
| static istring | unique_shared_mem_identifier (int sequencer) |
| returns a unique identifier for a shared memory chunk. | |
Provides a means to create shared memory chunks and access them from anywhere in a program or from cooperating programs.
Definition at line 32 of file shared_memory.h.
| shared_memory::shared_memory | ( | int | size, | |
| 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.
Definition at line 46 of file shared_memory.cpp.
References FUNCDEF, rendezvous::lock(), negative(), NULL, O_CREAT, O_EXCL, O_RDWR, portable::system_error(), portable::system_error_text(), and rendezvous::unlock().
| shared_memory::~shared_memory | ( | ) | [virtual] |
cleans up the shared bit of memory as far as we're concerned.
if some other instance still has it opened, then it isn't destroyed for real yet.
Definition at line 121 of file shared_memory.cpp.
References close, identity(), NIL, and WHACK().
| shared_memory::IMPLEMENT_CLASS_NAME | ( | "shared_memory" | ) |
| bool shared_memory::valid | ( | ) | const [inline] |
this must be true for the shared_memory to be usable.
if it's false, then the memory chunk was never created.
Definition at line 50 of file shared_memory.h.
| int shared_memory::size | ( | ) | const [inline] |
| const istring & shared_memory::identity | ( | ) | const |
provides a peek at the name that this chunk was constructed with.
Definition at line 139 of file shared_memory.cpp.
Referenced by ~shared_memory().
| bool shared_memory::first_usage | ( | byte * | locked_memory, | |
| int | max_compare | |||
| ) |
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.
Definition at line 159 of file shared_memory.cpp.
| byte * 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.
Definition at line 166 of file shared_memory.cpp.
References rendezvous::lock().
| void shared_memory::unlock | ( | byte *& | to_unlock | ) |
returns control of the shared memory so others can access it.
calls to lock() must be paired up with calls to unlock().
Definition at line 172 of file shared_memory.cpp.
References rendezvous::unlock().
| istring shared_memory::unique_shared_mem_identifier | ( | int | sequencer | ) | [static] |
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.
Definition at line 149 of file shared_memory.cpp.
References portable::application_name(), filename::detooth_filename(), and portable::process_id().
1.5.1