An encapsulation of a block of memory that can be mapped by one or more (not necessarily related) processes; when one process changes the data in the block, the changes are immediately visible to the other processes.
More...
#include <SharedMemoryBlock.h++>
An encapsulation of a block of memory that can be mapped by one or more (not necessarily related) processes; when one process changes the data in the block, the changes are immediately visible to the other processes.
- Author
- Mark Lindner
◆ SharedMemoryBlock()
Construct a new SharedMemoryBlock.
The actual memory segment is not created and mapped until a call to attach() is made.
- Parameters
-
name | The name of the memory block. For maximal portability, the name should consist of at most 14 alphanumeric characters and should not contain slashes. |
size | The size of the memory block, in bytes. This size will be rounded up to the nearest multiple of the system page size. |
perm | The permissions with which to create the memory block, if it does not exist at the time of the attach(). |
◆ ~SharedMemoryBlock()
Destructor.
Detaches from the memory block.
◆ attach()
void attach |
( |
bool |
readOnly = false | ) |
|
Attach to the memory block, creating it if it does not yet exist.
- Parameters
-
readOnly | A flag indicating whether the memory block should be mapped for read-only access or read-write access. |
- Exceptions
-
◆ copyFrom()
Copy data from another memory block to this one.
The number of bytes copied is the minimum of the sizes of the two blocks. The blocks may not overlap.
- Parameters
-
other | The block to copy from. |
- Returns
- true if the copy succeeded, false if the blocks overlap.
◆ detach()
Detach from the memory block, and destroy it if no other process currently has it mapped.
◆ fill()
Fill the memory block with the given byte value.
◆ getBase() [1/2]
Get a pointer to the beginning of the memory block.
◆ getBase() [2/2]
const byte_t* getBase |
( |
| ) |
const |
|
inlineinherited |
Get a pointer to the beginning of the memory block.
◆ getName()
Get the name of the memory block.
◆ getSize()
Get the size of the memory block.
◆ indexOf()
Find the first occurrence of a given byte value in the memory block, starting at a given index.
- Parameters
-
val | The value to search for. |
startIndex | The index to begin searching at. |
- Returns
- The index of the first matching value, or -1 if not found.
◆ moveFrom()
Copy data from another (possibly overlapping) memory block to this one.
The number of bytes copied is the minimum of the sizes of the two blocks.
- Parameters
-
other | The block to copy from. Note that the copy may result in both blocks being modified, if the source area overlaps the target area. |
◆ operator!()
Test if the base of the block is NULL.
◆ operator!=()
◆ operator==()
◆ operator[]() [1/2]
byte_t operator[] |
( |
int |
index | ) |
const |
|
inherited |
Bounds-checked access.
- Exceptions
-
◆ operator[]() [2/2]
byte_t & operator[] |
( |
int |
index | ) |
|
|
inherited |
Bounds-checked access.
- Exceptions
-
◆ setBase()
Overridden to have no effect.
Reimplemented from MemoryBlock.
◆ setSize()
void setSize |
( |
size_t |
size | ) |
|
|
virtual |
Overridden to have no effect.
◆ zero()
◆ _base
A pointer to the beginning of the memory block.
◆ _size
The size of the memory block, in bytes.
The documentation for this class was generated from the following files: