native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
C allocation and mapping ownership

Concepts

concept  native::trivially_destructible

Classes

struct  native::c_free

Typedefs

template<trivially_destructible T>
using native::unique_c_ptr = std::unique_ptr<T, c_free>
using native::unique_str = unique_c_ptr<char const>

Functions

unique_str native::dup (char const *str) noexcept

Detailed Description

Small unique_ptr deleters for allocations made outside C++ new/delete. They do not construct or destroy objects in the allocation.

void common_utilities() {
using namespace native;
auto first = "vector"_ss;
auto second = "vector"_ss;
check(first == second && first.data() == second.data());
check(std::hash<static_string>{}(first) == std::hash<static_string>{}(second));
auto owned = native::dup(first.data());
if (owned) check(std::string_view(owned.get()) == "vector");
check(!native::type_of(first).empty());
auto half = native::fp16(1.5f);
check(static_cast<float>(half) == 1.5f);
}

Typedef Documentation

◆ unique_c_ptr

template<trivially_destructible T>
using native::unique_c_ptr = std::unique_ptr<T, c_free>
export

Exclusive ownership of C storage; move or reset it as with std::unique_ptr.

Definition at line 44 of file native.memory.ccm.

◆ unique_str

using native::unique_str = unique_c_ptr<char const>
export

A read-only C string whose allocation is released by std::free.

Definition at line 50 of file native.memory.ccm.

Function Documentation

◆ dup()

unique_str native::dup ( char const * str)
inlineexportnoexcept

Duplicate a C string into independent owned storage. Check for allocation failure.

void common_utilities() {
using namespace native;
auto first = "vector"_ss;
auto second = "vector"_ss;
check(first == second && first.data() == second.data());
check(std::hash<static_string>{}(first) == std::hash<static_string>{}(second));
auto owned = native::dup(first.data());
if (owned) check(std::string_view(owned.get()) == "vector");
check(!native::type_of(first).empty());
auto half = native::fp16(1.5f);
check(static_cast<float>(half) == 1.5f);
}
Precondition
str is non-null
Postcondition
result owns an independent null-terminated copy, or is null if allocation fails

Definition at line 60 of file native.memory.ccm.

Here is the caller graph for this function: