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.

Functions

Heap

public void Heap( vmo vmo)

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

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

The VMO must not be zero-sized.

~Heap

public void ~Heap()

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

GetVmo

public const zx::vmo & GetVmo()

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

Gets a reference to the underlying VMO.

Allocate

public zx_status_t Allocate(size_t min_size, BlockIndex * out_block)

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

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.

GetBlock

public Block * GetBlock(BlockIndex block)

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

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

data

public const uint8_t * data()

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

Return a pointer to the data buffer.

size

public size_t size()

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

Return the current usable size of the VMO.

TotalAllocatedBlocks

public size_t TotalAllocatedBlocks()

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

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

TotalDeallocatedBlocks

public size_t TotalDeallocatedBlocks()

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

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

TotalFailedAllocations

public size_t TotalFailedAllocations()

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

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

maximum_size

public size_t maximum_size()

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

Return the maximum size of the VMO.

SetHeaderBlock

public void SetHeaderBlock(Block *const hb)

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

Set header block.

GetHeaderBlock

public optional GetHeaderBlock()

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

Get header block.

Free

public void Free(BlockIndex block_index)

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

Free a |BlockIndex| allocated from this heap.