The class FBB::SharedSegment implements the shared memory data structure used by Bobcat's shared memory classes. Bobcat's SharedMemory class accesses or defines a shared memory segment, controlling all its read and write operations.
The requested amount of shared memory is always a lower bound to the maximum amount of shared memory that eventually may become available. When defining a SharedSegment object not all of its potentially available shared memory is immediately allocated. Shared memory will be allocated by the SharedSegment object once needed (up to a calculated maximum).
As a fictitious example: assume 100 kB of memory is requested, then the SharedSegment object, maintains a table of, e.g., 10 entries, each controlling the access to a shared memory block of 10 kB. These 10 kB blocks aren't immediately allocated, but become available once the program reads from or writes to addresses located in these data segments.
The class SharedSegment therefore defines a gateway, controlling access to and allocating required shared memory data segments. The mentioned table consists of nBlocks SharedBlock (sharedblock(3bobcat)) values, offering mutexes and IDs of shared data segments. The mutexes control which process has access to a particular block of shared data memory, and the IDs are either -1, meaning that their shared memory data segments has as not yet been allocated, or they contain the IDs of defined shared memory data segments.
The class SharedSegment's sole responsibility is to offer the framework as described. When used by a FBB::SharedMemory object different processes may gain access to different parts of the shared memory data without interfering each other's read and write actions.
No publicly accessible constructors have been defined for SharedSegment. A static member function create (see below) is available, returning a pointer to a shared memory segment, in which a SharedSegment has been defined.
An FBB::Exception is thrown if the shared memory data segment could not be allocated.
An FBB::Exception is thrown if the shared memory data segment could not be attached.
The created shared memory's ID is stored at *id. The remaining arguments define the potential number of shared memory data blocks (nBlocks); the size of these data blocks (segmentSize); and the shared memory's access rights (access, using the well-known octal value representation as used by (chmod(1)) to define access rights for the owner, the group and others).
An FBB::Exception is thrown if the shared memory data segment could not be created.
An FBB::Exception is thrown if shared memory data segment id could not be deleted.
By default, detaching the memory must succeed or an FBB::Exception is thrown. Throwing an exception on failure can be prevented by passing false as the member's second argument.
An FBB::Exception is thrown if the size of segment id could not be determined.