Shared memory support

The classes for tranferring the data through shared memory if the receiver and transmitter are on the same host

class Payload : public zenohcxx::Owned<::zc_owned_payload_t>

Reference to data buffer in shared memory with reference counting. When all instances of Payload are destroyed, the buffer is freed. It can be convenient if it’s necessary to resend the buffer to one or multiple receivers without copying it. This can be performed with Publisher::put_owned method.

Note

zenoh-c only

Methods

inline Payload rcinc() const

Clone reference to the payload buffer with incrementing it’s reference count.

Returns:

Reference to the payload buffer

inline const zenoh::BytesView &get_payload() const

Access the data in the payload buffer.

Returns:

BytesView object representing the data in the payload buffer

class Shmbuf : public zenohcxx::Owned<::zc_owned_shmbuf_t>

Memory buffer returned by shared memory manager ShmManager

Note

zenoh-c only

Methods

inline uintptr_t get_capacity() const

Returns the capacity of the SHM buffer in bytes.

Returns:

capacity of the SHM buffer in bytes

inline uintptr_t get_length() const

Returns the length of data in the SHM buffer in bytes.

Returns:

length of data

inline void set_length(uintptr_t length)

Set the length of data in the SHM buffer in bytes. Can’t be greater than the capacity.

Parameters:

length – length of the data

inline zenoh::Payload into_payload()

Returns the payload object with the data from the SHM buffer. The Shmbuf object itself is invalidated.

Returns:

Payload object with the data from the SHM buffer

inline uint8_t *ptr() const

Returns the pointer to the data in the SHM buffer as uint8_t*

Returns:

pointer to the data

inline char *char_ptr() const

Returns the pointer to the data in the SHM buffer as char*

Returns:

pointer to the data

inline std::string_view as_string_view() const

Returns pointer to data and length of the data as std::string_view

Returns:

std::string_view object representing the data in the SHM buffer

class ShmManager : public zenohcxx::Owned<::zc_owned_shm_manager_t>

Shared memory manager

Note

zenoh-c only

Constructors

friend std::variant<zenoh::ShmManager, zenoh::ErrorMessage> shm_manager_new(const zenoh::Session &session, const char *id, uintptr_t size)

Create a new shared memory manager. Allocate a new shared memory buffer or joins an existing one with the id

Parameters:
  • sessionSession object

  • id – string identifier of the shared memory manager

  • size – size of the shared memory buffer in bytes

Returns:

ShmManager object or zenoh::ErrorMessage if an error occurred

Methods

std::variant<zenoh::Shmbuf, zenoh::ErrorMessage> alloc(uintptr_t capacity) const

Allocate a new shared memory buffer Shmbuf with the given capacity.

Parameters:

capacity – capacity of buffer in bytes

Returns:

Shmbuf object or zenoh::ErrorMessage object if an error occurred

inline uintptr_t defrag() const

Perfrom defagmentation of the shared memory manager.

Returns:

The amount of memory defragmented in bytes

inline uintptr_t gc() const

Perform garbage collection of the shared memory manager.

Returns:

The amount of memory freed in bytes