Gin
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
SharedMemory Class Reference

Creates a block of shared memory. More...

#include <gin_sharedmemory.h>

Public Member Functions

 SharedMemory (const juce::String &name, int size)
 Creates or opens a shared memory block.
 
 ~SharedMemory ()
 Destructor.
 
void * getData ()
 Returns a pointer to the shared memory data.
 
int getSize ()
 Returns the actual size of the shared memory block in bytes.
 

Static Public Member Functions

static void remove (const juce::String &name)
 Removes a shared memory block by name.
 

Detailed Description

Creates a block of shared memory.

The first one to create the block sets the size otherwise it is ignored. The block may be a different size than requested, especially if it was already created.

On Unix based OSes, if a process using the block crashes, the block will leak. Clean it up later with remove() and it will be deleted when the last process stops using it. (No new processes will be able to attach)

On Windows the memory block will always disappear when the final process closes the handle / crashes.

Constructor & Destructor Documentation

◆ SharedMemory()

SharedMemory::SharedMemory ( const juce::String &  name,
int  size 
)

Creates or opens a shared memory block.

If a block with this name already exists, it will be opened and the size parameter is ignored. Otherwise, a new block is created with the specified size. The actual size may differ from the requested size, especially if the block already existed.

Parameters
nameThe unique system-wide name for this shared memory block
sizeThe desired size in bytes (only used when creating a new block)

◆ ~SharedMemory()

SharedMemory::~SharedMemory ( )

Destructor.

Detaches from the shared memory block.

On Windows, if this is the last process using the block, it will be deleted. On Unix systems, the block will persist until explicitly removed with remove().

Member Function Documentation

◆ remove()

static void SharedMemory::remove ( const juce::String &  name)
static

Removes a shared memory block by name.

On Unix systems, this marks the block for deletion. It will be deleted when the last process detaches. On Windows, this has no effect as blocks are automatically cleaned up.

Parameters
nameThe name of the shared memory block to remove

◆ getData()

void * SharedMemory::getData ( )

Returns a pointer to the shared memory data.

This pointer can be used to read from or write to the shared memory. All processes sharing this memory block will see the same data.

Returns
Pointer to the shared memory, or nullptr if the block is invalid

◆ getSize()

int SharedMemory::getSize ( )

Returns the actual size of the shared memory block in bytes.

This may differ from the requested size, especially if the block already existed when this SharedMemory object was created.

Returns
The size of the shared memory block in bytes

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