Shmex v0.1.0 Shmex.Native View Source
This module provides natively implemented functions allowing low-level operations on Posix shared memory. Use with caution!
Link to this section Summary
Functions
Creates guard for existing shared memory
Creates shared memory segment and adds a guard for it
Reads the contents of SHM and returns as binary
Reads cnt
bytes from SHM and returns as binary
Sets the capacity of SHM and updates the struct accordingly
Splits the contents of SHM into 2 by moving part of the data into a new SHM
Writes the binary into the SHM
Link to this section Functions
add_guard(Shmex.t()) :: Bunch.Type.try_t(Shmex.t())
Creates guard for existing shared memory.
This function should be only used when Shmex
struct was created by
some other NIF and even though the SHM exists, it’s guard field is set to nil
.
Trying to use it with SHM obtained via allocate/1
will result in error.
See also docs for allocate/1
allocate(payload :: Shmex.t()) :: Bunch.Type.try_t(Shmex.t())
Creates shared memory segment and adds a guard for it.
The guard associated with this memory segment is placed in returned
Shmex
struct. When the guard resource is deallocated by BEAM,
the shared memory is unlinked and will disappear from the system when last process
using it unmaps it
concat(left :: Shmex.t(), right :: Shmex.t()) :: Bunch.Type.try_t(Shmex.t())
read(payload :: Shmex.t()) :: Bunch.Type.try_t(binary())
Reads the contents of SHM and returns as binary
read(payload :: Shmex.t(), cnt :: non_neg_integer()) :: Bunch.Type.try_t(binary())
Reads cnt
bytes from SHM and returns as binary
cnt
should not be greater than payload.size
set_capacity(payload :: Shmex.t(), capacity :: pos_integer()) :: Bunch.Type.try_t(Shmex.t())
Sets the capacity of SHM and updates the struct accordingly
split_at(payload :: Shmex.t(), position :: non_neg_integer()) :: Bunch.Type.try_t({Shmex.t(), Shmex.t()})
Splits the contents of SHM into 2 by moving part of the data into a new SHM
payload
has to be an existing shm (obtained via allocate/1
).
It virtually trims the existing SHM to position
bytes by setting size
to position
(The actual data is still present) and the overlapping data is copied into the new SHM.
trim(payload :: Shmex.t(), bytes :: non_neg_integer()) :: Bunch.Type.try_t()
write(payload :: Shmex.t(), data :: binary()) :: Bunch.Type.try_t(Shmex.t())
Writes the binary into the SHM.
Overwrites existing content. Increases capacity to fit the data.