o size_tblockOffset()const:
The offset within the shared segment data block matching offset’s return value is returned. 0 is
returned if the SharedMemory object has not yet been connected to a shared memory block (or if the
offset happens to be at the block’s offset 0).
o voidclear():
First, the shared memory is locked. Next, all shared data segment are deleted, and the shared
memory’s own data are reset to indicate it is completely empty. Following this the shared memory
segment is unlocked again. Returning from clear the shared memory The FBB::SharedMemory object is
effectively re-initialized, with offset and nReadable returning 0.
An FBB::Exception is thrown if the SharedMemory object has not yet been connected to a shared
memory block.
o size_tdataSegmentSize()const:
Returns the size (in bytes) of shared memory data block. 0 is returned if the SharedMemory object
has not yet been connected to a shared memory block.
o intget():
First the FBB::SharedMemory object calls lock to lock the shared memory segment. Next the
character at offset is retrieved and offset is incremented. Then unlock is called, and the
retrieved character is returned. If offset is at least equal to nReadable,EOF is immediately
returned.
An FBB::Exception is thrown if the SharedMemory object has not yet been connected to a shared
memory block.
o intid()const:
The ID of the shared memory segment is returned. Following killid returns -1, indicating that the
shared segment cannot be used anymore (note that operator= can be used to re-initialize the
FBB::SharedMemory object).
o SharedType*install(std::streamsize*offset,Params&&...params):
This member was implemented as a member template, using typenameSharedType and typename...Params, allowing perfect forwarding of arguments to SharedType’s constructor.
This member installs a SharedType object at SharedMemory’s at SharedMemory’s first available
offset: either at the current offset, or (if SharedType’s size is too big to fit in the current
data block at offset) at the first byte of the next SharedSegment shared data block.
The actual offset where the SharedType object is installed is returned in *offset, unless a
nullptr is passed as install’s first argument.
A pointer to the installed SharedType is returned, with shmem.offset pointing just beyond
SharedType’s last byte.
The SharedType object is installed using placement new. E.g., the following example illustrates
how a SharedMutex(3bobcat) object can be installed at the first possible location of SharedMemoryshmem:
std::streamsize offset;
FBB::SharedMutex *mutexPtr = shmem.install<FBB::SharedMutex>(&offset);
If the installed object must be destroyed, its destructor must explicitly be called. E.g., to
destroy the Mutex pointed at by mutexPtr use mutexPtr->~SharedMutex().
An FBB::Exception is thrown if shmem could not install the object in its shared memory data
blocks.
o voidkill():
Without locking the shared memory all shared memory controlled by the SharedMemory object is
deleted. The SharedMemory object is unusable after returning from kill, with its id member returns
-1. Nothing happens if this member is called when the SharedMemory object has not yet been
connected to a shared memory block.
o std::streamsizemaxOffset()const:
The maximum possible offset that can be used with the shared memory segment is returned. The
members offset and nReadable never exceed the value returned by maxOffset. 0 is returned if the
SharedMemory object has not yet been connected to a shared memory block.
o std::streamsizenReadable()const:
The number of characters (bytes) that can be read from the beginning of the shared memory is
returned. 0 is returned if the SharedMemory object has not yet been connected to a shared memory
block.
o std::streamsizeoffset()const:
The offset within the shared memory segment (i.e., relative to the segment’s ios::beg position) is
returned. 0 is returned if the SharedMemory object has not yet been connected to a shared memory
block (or if the offset happens to be at the shared memory’s offset 0).
o char*ptr():
Returns 0 if offset()==maxOffset(). Otherwise it returns a pointer to the character at index
offset within the shared memory segment.
An FBB::Exception is thrown if the SharedMemory object has not yet been connected to a shared
memory block.
o intput(intch):
After locking the appropriate shared data segment, ch is written at position offset, incrementing
offset thereafter. If ch==EOF,EOF is immediately returned.
An FBB::Exception is thrown if the SharedMemory object has not yet been connected to a shared
memory block.
o intread(Type*value):
This member was implemented as a member template. It calls the next member, casting Type* to char*, and using sizeof(Type) as its second argument. The number of bytes actually read is returned.
This member returns -1 if initially offset was at least equal to nReadable.
An FBB::Exception is thrown if the SharedMemory object has not yet been connected to a shared
memory block.
o intread(char*data,std::streamsizelen):
While locking the appropriate shared data segment(s) at most len bytes are read from the shared
memory, starting at offset. The bytes read from shared memory are stored at data. The number of
bytes actually read is returned. This member returns -1 if initially offset was at least equal to
nReadable.
An FBB::Exception is thrown if the SharedMemory object has not yet been connected to a shared
memory block.
o intread(std::ios::off_typeoffset,Type*value,std::ios::seekdirorigin=std::ios::beg):
This member was implemented as a member template. After changing the SharedMemory’s offset to
offset (relative to origin), it calls the first read member, passing it value. The number of bytes
actually read is returned. This member returns -1 if initially offset was at least equal to
nReadable.
An FBB::Exception is thrown if the SharedMemory object has not yet been connected to a shared
memory block.
o voidremove():
The shared memory is locked, after which all shared memory controlled by the FBB::SharedMemory
object is deleted. The FBB::SharedMemory object is unusable after returning from remove.
An FBB::Exception is thrown if the SharedMemory object has not yet been connected to a shared
memory block.
o std::ios::pos_typeseek(std::ios::off_typeoffset,std::ios::seekdirorigin=std::ios::beg):
Moves the offset position relative to way. The value -1 is returned when seeking before offset 0
or beyond maxOffset, otherwise the offset relative to the begin location of the shared memory
(i.e, offset for origin==ios::beg) is returned. 0 is returned if the SharedMemory object has
not yet been connected to a shared memory block (or if the offset happens to be at the shared
memory’s offset 0).
o std::streamsizeshowmanyc()const:
The number of characters that can be read from the current shared segment data block is returned.
This member interrogates the number of readable characters in the shared memory segment. This
number may change while this member is being executed. In order to receive a stable return value,
calling functions should have obtained a lock on the shared memory segment before calling this
member. 0 is returned if the SharedMemory object has not yet been connected to a shared memory
block (or if the no characters can currently be read).
o voidswap(SharedMemory&other):
The current and other FBB::SharedMemory objects are swapped.
o booltruncate(std::streamsizeoffset):
If offset is not exceeding the value returned by nReadablenReadable is changed to offset and true
is returned. Otherwise false is returned, and the value returned by nReadable is not changed.
An FBB::Exception is thrown if the SharedMemory object has not yet been connected to a shared
memory block.
o intwrite(Typeconst*value):
This member was implemented as a member template. It calls the next member, casting Typeconst*
to charconst*, and using sizeof(Type) as its second argument. The number of bytes actually
written is returned. This member returns -1 if initially offset was at least equal to maxOffset.
An FBB::Exception is thrown if the SharedMemory object has not yet been connected to a shared
memory block.
o intwrite(charconst*data,std::streamsizelen):
The FBB::SharedMemory object calls lock to lock the shared memory, and writes at most len bytes
into the shared memory, starting at offset. Next, unlock is called. The number of bytes actually
written is returned. The member function returns -1 if initially offset is equal to maxOffset.
An FBB::Exception is thrown if the SharedMemory object has not yet been connected to a shared
memory block.
o intwrite(std::ios::off_typeoffset,Typeconst*value,std::ios::seekdirorigin=std::ios::beg):
This member was implemented as a member template. After changing the SharedMemory’s offset to
offset (relative to origin), it calls the first write member, passing it value. The number of
bytes actually written is returned. This member returns -1 if initially offset was at least equal
to maxOffset.
An FBB::Exception is thrown if the SharedMemory object has not yet been connected to a shared
memory block.