class Heap

Defined at line 29 of file ../../zircon/system/ulib/inspect/include/lib/inspect/cpp/vmo/heap.h

A buddy-allocated heap of blocks stored in a VMO.

|Heap| supports Allocate and Free operations to

allocate memory stored in a VMO. |Heap| allocations

touch a new page of the VMO (up to its capacity) only

when necessary to satisfy the allocation. This ensures

the VMO's default behavior of mapping all untouched

pages to a single physical "zero" page results in the

heap using the least amount of physical memory to

satisfy requests.

This class is not thread safe.

Public Methods

void Heap (zx::vmo vmo)

Create a new heap that allocates out of the given |vmo|.

The VMO must not be zero-sized.

Defined at line 25 of file ../../zircon/system/ulib/inspect/vmo/heap.cc

void ~Heap ()

Defined at line 34 of file ../../zircon/system/ulib/inspect/vmo/heap.cc

const zx::vmo & GetVmo ()

Gets a reference to the underlying VMO.

Defined at line 41 of file ../../zircon/system/ulib/inspect/vmo/heap.cc

zx_status_t Allocate (size_t min_size, BlockIndex * out_block)

Allocate a |BlockIndex| out of the heap that can contain at least |min_size| bytes.

Allocating a block larger that |kMaxOrderSize| bytes will fail.

Returns ZX_OK on success or an error on failure.

|out_block| will be set to the allocated block index on success only.

Warning: It is an error to destroy the heap without freeing all blocks first.

Defined at line 43 of file ../../zircon/system/ulib/inspect/vmo/heap.cc

Block * GetBlock (BlockIndex block)

Get a pointer to the |Block| for the given |Block|.

Defined at line 53 of file ../../zircon/system/ulib/inspect/include/lib/inspect/cpp/vmo/heap.h

const uint8_t * data ()

Return a pointer to the data buffer.

Defined at line 59 of file ../../zircon/system/ulib/inspect/include/lib/inspect/cpp/vmo/heap.h

size_t size ()

Return the current usable size of the VMO.

Defined at line 62 of file ../../zircon/system/ulib/inspect/include/lib/inspect/cpp/vmo/heap.h

size_t TotalAllocatedBlocks ()

Return the number of blocks allocated over the lifetime of the Heap.

Defined at line 65 of file ../../zircon/system/ulib/inspect/include/lib/inspect/cpp/vmo/heap.h

size_t TotalDeallocatedBlocks ()

Return the number of blocks deallocated over the lifetime of the Heap.

Defined at line 68 of file ../../zircon/system/ulib/inspect/include/lib/inspect/cpp/vmo/heap.h

size_t TotalFailedAllocations ()

Return the number of failed allocations over the lifetime of the Heap.

Defined at line 71 of file ../../zircon/system/ulib/inspect/include/lib/inspect/cpp/vmo/heap.h

size_t maximum_size ()

Return the maximum size of the VMO.

Defined at line 74 of file ../../zircon/system/ulib/inspect/include/lib/inspect/cpp/vmo/heap.h

void SetHeaderBlock (Block *const hb)

Set header block.

Defined at line 77 of file ../../zircon/system/ulib/inspect/include/lib/inspect/cpp/vmo/heap.h

std::optional<Block *> GetHeaderBlock ()

Get header block.

Defined at line 80 of file ../../zircon/system/ulib/inspect/include/lib/inspect/cpp/vmo/heap.h

void Free (BlockIndex block_index)

Free a |BlockIndex| allocated from this heap.

Defined at line 96 of file ../../zircon/system/ulib/inspect/vmo/heap.cc