#include <mapped.h>
Inheritance diagram for ucommon::MappedMemory:
Public Member Functions | |
caddr_t | addr (void) |
Get starting address of mapped segment. | |
bool | copy (size_t offset, void *buffer, size_t size) |
Copy memory from specific offset within the mapped memory segment. | |
size_t | len (void) |
Get size of mapped segment. | |
MappedMemory (char *name) | |
Provide read-only mapped access to an existing named shared memory segment. | |
MappedMemory (char *name, size_t size) | |
Construct a read/write access mapped shared segment of memory of a known size. | |
void * | offset (size_t offset) |
Get memory from a specific offset within the mapped memory segment. | |
operator bool () | |
Test if map active. | |
bool | operator! () |
Test if map is inactive. | |
void | release (void) |
Unmap memory segment. | |
void * | sbrk (size_t size) |
Extend size of managed heap on shared memory segment. | |
virtual | ~MappedMemory () |
Unmap memory segment. | |
Static Public Member Functions | |
static void | disable (void) |
An API that allows "disabling" of publishing shared memory maps. | |
static void | remove (char *name) |
Destroy a previously existing memory segment under the specified name. | |
Protected Member Functions | |
void | create (char *name, size_t size=(size_t) 0) |
Supporting function to construct a new or access an existing shared memory segment. | |
virtual void | fault (void) |
Handler for failure to map (allocate) memory. | |
virtual void * | invalid (void) |
Handler to invoke in derived class when accessing outside the shared memory segment boundary. | |
Protected Attributes | |
bool | erase |
char | idname [65] |
size_t | size |
size_t | used |
A logical name is used which might map to something that is invoked from a call like shm_open or a named w32 mapped swap segment. This is meant to support mapping a vector onto shared memory and is often used as a supporting class for our shared memory access templates.
Definition at line 58 of file mapped.h.
ucommon::MappedMemory::MappedMemory | ( | char * | name, | |
size_t | size | |||
) |
Construct a read/write access mapped shared segment of memory of a known size.
This constructs a new memory segment.
name | of segment. | |
size | of segment. |
ucommon::MappedMemory::MappedMemory | ( | char * | name | ) |
Provide read-only mapped access to an existing named shared memory segment.
The size of the map is found by the size of the already existing segment.
name | of existing segment. |
caddr_t ucommon::MappedMemory::addr | ( | void | ) | [inline] |
bool ucommon::MappedMemory::copy | ( | size_t | offset, | |
void * | buffer, | |||
size_t | size | |||
) |
Copy memory from specific offset within the mapped memory segment.
This function assures the copy is not in the middle of being modified.
offset | from start of segment. | |
buffer | to copy into. | |
size | of object to copy. |
void ucommon::MappedMemory::create | ( | char * | name, | |
size_t | size = (size_t) 0 | |||
) | [protected] |
Supporting function to construct a new or access an existing shared memory segment.
Used by primary constructors.
name | of segment to create or access. | |
size | of segment if creating new. Use 0 for read-only access. |
static void ucommon::MappedMemory::disable | ( | void | ) | [static] |
An API that allows "disabling" of publishing shared memory maps.
This may be useful when an app doesn't want to use shared memory as a runtime or build option, but does not want to have to be "recoded" explicitly for non-shared memory either. Basically it substitutes a dummy map running on the local heap.
size_t ucommon::MappedMemory::len | ( | void | ) | [inline] |
void* ucommon::MappedMemory::offset | ( | size_t | offset | ) |
Get memory from a specific offset within the mapped memory segment.
offset | from start of segment. Will fault if past end. |
ucommon::MappedMemory::operator bool | ( | ) | [inline] |
bool ucommon::MappedMemory::operator! | ( | ) | [inline] |
static void ucommon::MappedMemory::remove | ( | char * | name | ) | [static] |
Destroy a previously existing memory segment under the specified name.
This is used both before creating a new one, and after a publishing process unmaps the segment it created.
name | of segment to remove. |
void* ucommon::MappedMemory::sbrk | ( | size_t | size | ) |
Extend size of managed heap on shared memory segment.
This does not change the size of the mapped segment in any way, only that of any heap space that is being allocated and used from the mapped segment.
size | of space requested. Will fault if past end of segment. |