Open 3D Engine AzCore API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::SharedMemory Class Reference

#include <SharedMemory.h>

Inherits AZ::SharedMemory_Unimplemented.

Inherited by AZ::SharedMemoryRingBuffer.

Public Types

typedef AZStd::lock_guard< SharedMemoryMemoryGuard
 
- Public Types inherited from AZ::SharedMemory_Common
enum  AccessMode { ReadOnly , ReadWrite }
 
enum  CreateResult { CreateFailed , CreatedNew , CreatedExisting }
 

Public Member Functions

CreateResult Create (const char *name, unsigned int size, bool openIfCreated=false)
 Create a shared memory block. If openIfCreated is false all memory will be cleared to 0.
 
bool Open (const char *name)
 Open an existing shared memory block. If the block doesn't exist we will return false otherwise true.
 
bool IsReady () const
 
void Close ()
 
bool Map (AccessMode mode=ReadWrite, unsigned int size=0)
 Maps to the created map. If size == 0 it will map the whole memory.
 
bool IsMapped () const
 
bool UnMap ()
 
void lock ()
 Naming is conforming with AZStd::lock_guard/unique_lock/etc.
 
bool try_lock ()
 
void unlock ()
 
bool IsLockAbandoned ()
 
const char * GetName () const
 
void * Data ()
 
const void * Data () const
 
unsigned int DataSize () const
 
void Clear ()
 Sets all data (if mapped to 0)
 

Protected Types

using Platform = SharedMemory_Platform
 

Protected Member Functions

 SharedMemory (const SharedMemory &)
 
SharedMemoryoperator= (const SharedMemory &)
 
- Protected Member Functions inherited from AZ::SharedMemory_Unimplemented
bool IsReady () const
 
bool IsMapHandleValid () const
 
CreateResult Create (const char *name, unsigned int size, bool openIfCreated)
 
bool Open (const char *name)
 
void Close ()
 
bool Map (AccessMode mode, unsigned int size)
 
bool UnMap ()
 
void lock ()
 
bool try_lock ()
 
void unlock ()
 
bool IsLockAbandoned ()
 
bool IsWaitFailed () const
 

Protected Attributes

void * m_data
 
- Protected Attributes inherited from AZ::SharedMemory_Unimplemented
void * m_globalMutex = nullptr
 
- Protected Attributes inherited from AZ::SharedMemory_Common
char m_name [128]
 
void * m_mappedBase
 
unsigned int m_dataSize
 

Additional Inherited Members

- Static Protected Member Functions inherited from AZ::SharedMemory_Unimplemented
static int GetLastError ()
 

Detailed Description

Shared memory is a helper class to provide shared memory for IPC (Inter Process Communication). Technically this is the fastest way to communicate between two process on the same machine. Obviously for remote data exchange you will need to use Sockets/DCOM/etc.

Member Function Documentation

◆ IsLockAbandoned()

bool AZ::SharedMemory::IsLockAbandoned ( )

This function will return correct result only when you own the lock (you are inside lock()/unlock(). Otherwise it will always return false. IMPORTANT: It's recommended that you check after each call to lock if the mutex was abandoned and if so to reset shared memory as the state is unknown. As usual there are exceptional cases it which this can be fine, this is why we don't do it automatically.


The documentation for this class was generated from the following file: