View Source Shmex (Shmex v0.5.1)
This module allows using data placed in POSIX shared memory on POSIX compliant systems.
Defines a struct representing the actual shared memory object. The struct
should not be modified, and should always be passed around as a whole - see
Shmex.t/0
Summary
Types
Struct describing data kept in shared memory. Should not be modified and should always be passed around as a whole
Functions
Creates a new, empty shared memory area with the given capacity
Ensures that shared memory is not garbage collected at the point of executing this function.
Creates a new shared memory area filled with the existing data.
Creates a new shared memory area initialized with data
and sets its capacity.
Sets the capacity of shared memory area.
Returns shared memory contents as a binary.
Types
@type t() :: %Shmex{ capacity: pos_integer(), guard: reference() | nil, name: binary() | nil, size: non_neg_integer() }
Struct describing data kept in shared memory. Should not be modified and should always be passed around as a whole
...including passing to the native code - there are functions in :shmex_lib
(a native library exported via Bundlex) that will allow to transform Elixir
struct into a C struct and then access the shared memory from the native code.)
Shared memory should be available as long as the associated struct is not garbage collected.
Functions
@spec empty(capacity :: pos_integer()) :: t()
Creates a new, empty shared memory area with the given capacity
@spec ensure_not_gc(t()) :: :ok
Ensures that shared memory is not garbage collected at the point of executing this function.
Useful when passing shared memory to other OS process, to prevent it from being garbage collected until received and mapped by that process.
Creates a new shared memory area filled with the existing data.
@spec new(data :: binary(), capacity :: pos_integer()) :: t()
Creates a new shared memory area initialized with data
and sets its capacity.
The actual capacity is the greater of passed capacity and data size
@spec set_capacity(t(), pos_integer()) :: t()
Sets the capacity of shared memory area.
If the capacity is smaller than the current size, data will be discarded and size modified
Returns shared memory contents as a binary.