Skip to content

ludus::foundation::SharedString

Ludus Wiki · API overview · Browse API

Class

Immutable bytes shared by copies, without copy-on-write.
A handle is one pointer to a private block that holds an atomic retain count, the allocation domain, the byte count and the zero-terminated bytes. Empty has no allocation. Copies retain the same block; the bytes never change while any handle refers to them. CreateShared and CopyToString are the explicit, fallible copies in and out.
Separate handles may be copied/destroyed on different threads after publication; synchronize access to the same handle externally. Publish a handle to another thread through a queue, mutex or release/acquire handoff. The allocation domain must outlive all shared owners and must accept the final Free from whichever thread releases the last handle.

Declared in modules/foundation/strings/include/ludus/foundation/strings/shared_string.hpp

#include <ludus/foundation/strings/shared_string.hpp>
class ludus::foundation::SharedString final

Methods

SharedString

ludus::foundation::SharedString::SharedString() noexcept=default
Creates an empty handle; does not allocate.

Declared in modules/foundation/strings/include/ludus/foundation/strings/shared_string.hpp

~SharedString

ludus::foundation::SharedString::~SharedString() noexcept
Releases this handle's reference; the last release frees the block through its domain.

Declared in modules/foundation/strings/include/ludus/foundation/strings/shared_string.hpp

SharedString

ludus::foundation::SharedString::SharedString(const SharedString &other) noexcept
Shares other's block without allocating or copying bytes.
If the retain count saturates, the block is pinned (never freed) and a check failure is reported instead of wrapping the count.

Declared in modules/foundation/strings/include/ludus/foundation/strings/shared_string.hpp

operator=

SharedString & ludus::foundation::SharedString::operator=(const SharedString &other) noexcept
Retains other's block before releasing this handle's, so self-assignment is safe.

Related types: SharedString

Declared in modules/foundation/strings/include/ludus/foundation/strings/shared_string.hpp

SharedString

ludus::foundation::SharedString::SharedString(SharedString &&other) noexcept
Takes other's block without touching the retain count; other becomes empty.

Declared in modules/foundation/strings/include/ludus/foundation/strings/shared_string.hpp

operator=

SharedString & ludus::foundation::SharedString::operator=(SharedString &&other) noexcept
Releases this handle's block, then takes other's; other becomes empty. Self-move does nothing.

Related types: SharedString

Declared in modules/foundation/strings/include/ludus/foundation/strings/shared_string.hpp

GetSize

usize ludus::foundation::SharedString::GetSize() const noexcept
Number of shared bytes, excluding the terminating zero; zero for an empty handle.

Related types: usize

Declared in modules/foundation/strings/include/ludus/foundation/strings/shared_string.hpp

IsEmpty

bool ludus::foundation::SharedString::IsEmpty() const noexcept
True when GetSize is zero.

Declared in modules/foundation/strings/include/ludus/foundation/strings/shared_string.hpp

GetView

std::string_view ludus::foundation::SharedString::GetView() const &noexcept
Borrowed counted view of the shared bytes, which may contain zero bytes.
Valid while some handle keeps the block alive; a view taken from a handle that is then reassigned, moved from or destroyed may dangle once that was the last reference.

Declared in modules/foundation/strings/include/ludus/foundation/strings/shared_string.hpp

GetView

std::string_view ludus::foundation::SharedString::GetView() const &&=delete
Deleted so a view cannot outlive a temporary handle that may hold the last reference.

Declared in modules/foundation/strings/include/ludus/foundation/strings/shared_string.hpp

GetData

const char * ludus::foundation::SharedString::GetData() const &noexcept
Borrowed pointer to the shared bytes; never null.
GetData()[GetSize()] is always zero; an empty handle returns a static empty string. Lifetime is the same as GetView.

Declared in modules/foundation/strings/include/ludus/foundation/strings/shared_string.hpp

GetData

const char * ludus::foundation::SharedString::GetData() const &&=delete
Deleted so a pointer cannot outlive a temporary handle that may hold the last reference.

Declared in modules/foundation/strings/include/ludus/foundation/strings/shared_string.hpp

Members

operator==

bool operator==(const SharedString &left, const SharedString &right) noexcept
Text equality: the same block, or equal bytes in different blocks.
Two independently created handles with equal bytes compare equal; equality is not storage identity. Empty handles are equal.

Related types: SharedString

Declared in modules/foundation/strings/include/ludus/foundation/strings/shared_string.hpp