Base Framework
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
SharedMemory Class Reference

Shared memory. More...

#include <base/mem/SharedMemory.h>

Inherits Object.

Classes

class  SharedMemoryImpl
 

Public Types

enum  Access {
  READ = 1, WRITE = 2, READWRITE = READ|WRITE, EXECUTE = 4,
  ANY = READWRITE|EXECUTE
}
 
enum  Option { PREPARE = 1, CLEAR = 2 }
 

Public Member Functions

 SharedMemory (const String &path, const FileRegion &region, unsigned int access, unsigned int options)
 
 SharedMemory (const SharedMemory &copy) noexcept
 
SharedMemoryoperator= (const SharedMemory &assign) noexcept
 
long long getOffset () const noexcept
 
unsigned int getSize () const noexcept
 
const FileRegiongetRegion () const noexcept
 
uint8 * getBytes () noexcept
 
const uint8 * getBytes () const noexcept
 
void lock ()
 
void unlock ()
 
void setProtection (unsigned int access)
 
void synchronize (bool asynchronous=false)
 
void clear () noexcept
 

Static Public Member Functions

static MemorySize getGranularity () noexcept
 

Public Attributes

Reference< SharedMemoryImplsharedMemory
 

Detailed Description

Shared memory.

Shared memory support.

Version
1.0

Member Enumeration Documentation

◆ Access

Access to shared memory.

Enumerator
READ 

Read access.

WRITE 

Write access.

READWRITE 

Read and write access.

EXECUTE 

Execute access.

ANY 

Read, write, and execute access.

◆ Option

Options.

Enumerator
PREPARE 

Specifies that the file should be extended to the specified file region.

CLEAR 

Specifies that the region should be initialized with zeros.

Constructor & Destructor Documentation

◆ SharedMemory() [1/2]

SharedMemory::SharedMemory ( const String path,
const FileRegion region,
unsigned int  access,
unsigned int  options 
)

Initializes shared memory object.

Parameters
pathThe path of the file.
regionThe file region to map into memory.
accessThe required access.
optionsThe options.

◆ SharedMemory() [2/2]

SharedMemory::SharedMemory ( const SharedMemory copy)
noexcept

Initializes object by object.

Member Function Documentation

◆ clear()

void SharedMemory::clear ( )
noexcept

Fills the memory with zeros.

◆ getBytes() [1/2]

const uint8* SharedMemory::getBytes ( ) const
inlinenoexcept

Returns the shared bytes for non-modifying access.

◆ getBytes() [2/2]

uint8* SharedMemory::getBytes ( )
inlinenoexcept

Returns the shared bytes for modifying access.

◆ getGranularity()

static MemorySize SharedMemory::getGranularity ( )
staticnoexcept

Returns the granularity of addresses/offsets within the shared memory block and file object.

◆ getOffset()

long long SharedMemory::getOffset ( ) const
inlinenoexcept

Returns the offset within the file of the mapped region.

◆ getRegion()

const FileRegion& SharedMemory::getRegion ( ) const
inlinenoexcept

Returns the region of the mapped.

◆ getSize()

unsigned int SharedMemory::getSize ( ) const
inlinenoexcept

Returns the size of the map.

◆ lock()

void SharedMemory::lock ( )

Locks the memory.

◆ operator=()

SharedMemory& SharedMemory::operator= ( const SharedMemory assign)
noexcept

Assignment of object by object.

◆ setProtection()

void SharedMemory::setProtection ( unsigned int  access)

Sets the desired protection of the shared memory.

◆ synchronize()

void SharedMemory::synchronize ( bool  asynchronous = false)

Synchronize memory with file.

Parameters
asynchronousAllows the method to return before all data has been written. The default is false.

◆ unlock()

void SharedMemory::unlock ( )

Unlocks the memory.

Member Data Documentation

◆ sharedMemory

Reference<SharedMemoryImpl> SharedMemory::sharedMemory

The internal shared memory representation.