# recordingmicroallocator

Allocation accounting for memory diagnostics.

## tflite::RecordingMicroAllocator

`class` · `cpp`

```cpp
class RecordingMicroAllocator : public tflite::MicroAllocator
```

Utility subclass of `MicroAllocator` that records all allocations inside the arena. A summary of allocations can be logged through the ErrorReporter by invoking LogAllocations(). This special allocator requires an instance of RecordingSingleArenaBufferAllocator to capture allocations in the head and tail. Arena allocation recording can be retrieved by type through the `GetRecordedAllocation()` function. This class should only be used for auditing memory usage or integration testing.

Source: `tensorflow/lite/micro/recording_micro_allocator.h:60`

### tflite::RecordingMicroAllocator::Create

`method` · `cpp`

```cpp
static RecordingMicroAllocator * tflite::RecordingMicroAllocator::Create(uint8_t *tensor_arena, size_t arena_size)
```

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| tensor_arena | uint8_t * | Required |  |
| arena_size | size_t | Required |  |

Source: `tensorflow/lite/micro/recording_micro_allocator.h:62`

### tflite::RecordingMicroAllocator::GetDefaultTailUsage

`method` · `cpp`

```cpp
static size_t tflite::RecordingMicroAllocator::GetDefaultTailUsage()
```

Returns the fixed amount of memory overhead of `RecordingMicroAllocator`.

Source: `tensorflow/lite/micro/recording_micro_allocator.h:66`

### tflite::RecordingMicroAllocator::GetRecordedAllocation

`method` · `cpp`

```cpp
RecordedAllocation tflite::RecordingMicroAllocator::GetRecordedAllocation(RecordedAllocationType allocation_type) const
```

Returns the recorded allocations information for a given allocation type.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| allocation_type | RecordedAllocationType | Required |  |

Source: `tensorflow/lite/micro/recording_micro_allocator.h:69`

### tflite::RecordingMicroAllocator::GetSimpleMemoryAllocator

`method` · `cpp`

```cpp
const RecordingSingleArenaBufferAllocator * tflite::RecordingMicroAllocator::GetSimpleMemoryAllocator() const
```

Source: `tensorflow/lite/micro/recording_micro_allocator.h:72`

### tflite::RecordingMicroAllocator::PrintAllocations

`method` · `cpp`

```cpp
void tflite::RecordingMicroAllocator::PrintAllocations() const
```

Logs out through the ErrorReporter all allocation recordings by type defined in `RecordedAllocationType`.

Source: `tensorflow/lite/micro/recording_micro_allocator.h:76`

### tflite::RecordingMicroAllocator::AllocatePersistentBuffer

`method` · `cpp`

```cpp
void * tflite::RecordingMicroAllocator::AllocatePersistentBuffer(size_t bytes)
```

Allocates persistent buffer which has the same life time as the allocator. The memory is immediately available and is allocated from the tail of the arena.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| bytes | size_t | Required |  |

Source: `tensorflow/lite/micro/recording_micro_allocator.h:78`

### tflite::RecordingMicroAllocator::AllocateNodeAndRegistrations

`method` · `cpp`

```cpp
TfLiteStatus tflite::RecordingMicroAllocator::AllocateNodeAndRegistrations(
    const Model *model,
    SubgraphAllocations *subgraph_allocations
)
```

Allocates an array in the arena to hold pointers to the node and registration pointers required to represent the inference graph of the model.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| model | const Model * | Required |  |
| subgraph_allocations | SubgraphAllocations * | Required |  |

Source: `tensorflow/lite/micro/recording_micro_allocator.h:81`

### tflite::RecordingMicroAllocator::AllocateTfLiteEvalTensors

`method` · `cpp`

```cpp
TfLiteStatus tflite::RecordingMicroAllocator::AllocateTfLiteEvalTensors(
    const Model *model,
    SubgraphAllocations *subgraph_allocations
)
```

Allocates the list of persistent TfLiteEvalTensors that are used for the "eval" phase of model inference. These structs will be the source of truth for all tensor buffers.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| model | const Model * | Required |  |
| subgraph_allocations | SubgraphAllocations * | Required |  |

Source: `tensorflow/lite/micro/recording_micro_allocator.h:83`

### tflite::RecordingMicroAllocator::AllocateVariables

`method` · `cpp`

```cpp
TfLiteStatus tflite::RecordingMicroAllocator::AllocateVariables(
    const SubGraph *subgraph,
    TfLiteEvalTensor *eval_tensors,
    const int32_t *offline_planner_offsets
)
```

Allocates persistent tensor buffers for variable tensors in the subgraph. Online and offline variable tensors are handled differently hence the offline_planner_offsets parameter is needed.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| subgraph | const SubGraph * | Required |  |
| eval_tensors | TfLiteEvalTensor * | Required |  |
| offline_planner_offsets | const int32_t * | Required |  |

Source: `tensorflow/lite/micro/recording_micro_allocator.h:85`

### tflite::RecordingMicroAllocator::AllocatePersistentTfLiteTensorInternal

`method` · `cpp`

```cpp
TfLiteTensor * tflite::RecordingMicroAllocator::AllocatePersistentTfLiteTensorInternal()
```

TODO(b/162311891): Once all kernels have been updated to the new API drop this method. It is only used to record `TfLiteTensor` persistent allocations.

Source: `tensorflow/lite/micro/recording_micro_allocator.h:90`

### tflite::RecordingMicroAllocator::PopulateTfLiteTensorFromFlatbuffer

`method` · `cpp`

```cpp
TfLiteStatus tflite::RecordingMicroAllocator::PopulateTfLiteTensorFromFlatbuffer(
    const Model *model,
    TfLiteTensor *tensor,
    int tensor_index,
    int subgraph_index,
    bool allocate_temp
)
```

TODO(b/162311891): Once all kernels have been updated to the new API drop this function since all allocations for quantized data will take place in the temp section.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| model | const Model * | Required |  |
| tensor | TfLiteTensor * | Required |  |
| tensor_index | int | Required |  |
| subgraph_index | int | Required |  |
| allocate_temp | bool | Required |  |

Source: `tensorflow/lite/micro/recording_micro_allocator.h:95`
