class Arena

Defined at line 39 of file ../../sdk/lib/driver/runtime/include/lib/fdf/cpp/arena.h

C++ wrapper for an arena, with RAII semantics. Automatically destroys

the reference to the runtime arena object when it goes out of scope.

If there are no more references to the arena, all memory associated with

the arena will be freed.

|fdf::Arena::Create| will return a reference to a newly created runtime arena object.

Passing an arena to |fdf::Channel::Write| will create and transfer a new reference to

that same arena, and does not take ownership of your arena reference.

# Thread safety

This class is thread-unsafe.

# Example

constexpr fdf_arena_tag_t kTag = 'EXAM';

fdf::Arena arena(kTag);

// Allocate new blocks of memory.

void* addr1 = arena.Allocate(arena, 0x1000);

void* addr2 = arena.Allocate(arena, 0x2000);

// Use the allocated memory...

Public Methods

void Arena (fdf_arena_t * arena)

Defined at line 41 of file ../../sdk/lib/driver/runtime/include/lib/fdf/cpp/arena.h

void Arena (fdf_arena_tag_t tag)

Creates an FDF Arena for allocating memory. This can never fail.

|tag| provides a hint to the runtime so that it may be more efficient.

For example, adjusting the size of the buffer backing the arena to the expected

total size of allocations. It may also be surfaced in debug information.

Defined at line 48 of file ../../sdk/lib/driver/runtime/include/lib/fdf/cpp/arena.h

zx::result<Arena> Create (uint32_t options, fdf_arena_tag_t tag)

Creates a FDF arena for allocating memory.

|tag| provides a hint to the runtime so that it may be more efficient.

For example, adjusting the size of the buffer backing the arena to the expected

total size of allocations. It may also be surfaced in debug information.

# Errors

ZX_ERR_INVALID_ARGS: |options| is any value other than 0.

ZX_ERR_NO_MEMORY: Failed due to a lack of memory.

Defined at line 61 of file ../../sdk/lib/driver/runtime/include/lib/fdf/cpp/arena.h

void Arena (const Arena & to_copy)

Arena cannot be copied.

Defined at line 71 of file ../../sdk/lib/driver/runtime/include/lib/fdf/cpp/arena.h

Arena & operator= (const Arena & other)

Defined at line 72 of file ../../sdk/lib/driver/runtime/include/lib/fdf/cpp/arena.h

void Arena (Arena && other)

Arena can be moved. Once moved, invoking a method on an instance will

yield undefined behavior.

Moving the arena does not move any data allocated for |fidl::AnyArena|.

Defined at line 78 of file ../../sdk/lib/driver/runtime/include/lib/fdf/cpp/arena.h

Arena & operator= (Arena && other)

Defined at line 79 of file ../../sdk/lib/driver/runtime/include/lib/fdf/cpp/arena.h

void ~Arena ()

Defined at line 84 of file ../../sdk/lib/driver/runtime/include/lib/fdf/cpp/arena.h

void * Allocate (size_t bytes)

Returns a pointer to allocated memory of size |bytes|. The memory is managed by the arena

until it is freed by |Free|, or the arena is destroyed.

Defined at line 88 of file ../../sdk/lib/driver/runtime/include/lib/fdf/cpp/arena.h

void Free (void * ptr)

Hints to the arena that the |ptr| previously allocated by |Allocate| may be reclaimed.

Memory is not guaranteed to be reclaimed until the arena is destroyed.

Asserts if the memory is not managed by the arena.

Defined at line 93 of file ../../sdk/lib/driver/runtime/include/lib/fdf/cpp/arena.h

template <typename T>
bool Contains (const T * ptr)

Returns whether the memory region corresponding to |ptr| resides entirely within memory

managed by the |arena|.

# Example

MyStruct* ptr = static_cast

<MyStruct

*>(arena.Allocate(sizeof(size_t)));

bool contains = arena.Contains

<MyStruct

>(ptr);

Defined at line 103 of file ../../sdk/lib/driver/runtime/include/lib/fdf/cpp/arena.h

void reset (fdf_arena_t * arena)

Defined at line 107 of file ../../sdk/lib/driver/runtime/include/lib/fdf/cpp/arena.h

void close ()

Defined at line 112 of file ../../sdk/lib/driver/runtime/include/lib/fdf/cpp/arena.h

fdf_arena_t * release ()

Defined at line 120 of file ../../sdk/lib/driver/runtime/include/lib/fdf/cpp/arena.h

uint8_t * Allocate (size_t item_size, size_t count, void (*)(uint8_t *, size_t) destructor_function)

Implementation of |fidl::AnyArena|.

Defined at line 127 of file ../../sdk/lib/driver/runtime/include/lib/fdf/cpp/arena.h

fdf_arena_t * get ()

Defined at line 132 of file ../../sdk/lib/driver/runtime/include/lib/fdf/cpp/arena.h