Skip to content

shared_memory shared_memory

Alairion edited this page May 8, 2021 · 10 revisions

nes::shared_memory::shared_memory

Functions

(1) constexpr shared_memory() noexcept = default;
(2) explicit shared_memory(const std::string& name, std::uint64_t size);
(3) explicit shared_memory(const std::string& name, shared_memory_options options = shared_memory_options::none);
(4) shared_memory(const shared_memory&) = delete;
(5) shared_memory(shared_memory&& other) noexcept;
  1. Constructs an empty shared memory. A default-constructed shared memory object is not associated with any memory.
  2. Creates a new shared memory object with the specified name and size. The newly created shared memory is filled with 0.
  3. Opens an existing shared memory object. If options is nes::shared_memory_options::constant then the shared memory object can only be mapped for read-only access.
  4. Deleted copy-constructor.
  5. Move constructor. Initializes the new shared memory with the content other. After this call, other does no longer represents any shared memory object.

Parameters

Name Description
name The UTF-8 encoded name of the shared memory object. The real name of the shared memory object is shared_memory_root + name.
size The requested size, in bytes, of the shared memory object. The newly created shared memory object has a size of at least size bytes.
options Additional flags. nes::shared_memory_options::constant prevents from read-write access to the shared memory.
other An instance of nes::shared_memory

Preconditions

name must not be empty.
size must be more than 0.
options must be nes::shared_memory_options::none or nes::shared_memory_options::constant.

Complexity

  1. Explicit.
  2. Explicit.
  3. Deleted.

Exceptions

  1. Does not throw.
  2. May throw a std::runtime_error if the shared memory can not be allocated.
  3. May throw a std::runtime_error if the shared memory can not be opened.
  4. Deleted.
  5. Does not throw.

Implementation details

  1. On Windows, the shared memory object is created using CreateFileMappingW with an invalid file handle
    On Posix systems, the shared memory object is created using shm_open, followed by a call to ftruncate
  2. On Windows, the shared memory object is opened using OpenFileMappingW
    On Posix systems, the shared memory object is opened shm_open

Clone this wiki locally