# micromemoryplanner

Interface for planning reusable buffers.

## tflite::MicroMemoryPlanner

`class` · `cpp`

```cpp
class MicroMemoryPlanner
```

Interface class for planning the layout of memory buffers during the execution of a graph. It's designed to be used by a client that iterates in any order through the buffers it wants to lay out, and then calls the getter functions for information about the calculated layout. For example:

SomeMemoryPlanner planner; planner.AddBuffer(100, 0, 1); // `Buffer` 0 planner.AddBuffer(50, 2, 3); // `Buffer` 1 planner.AddBuffer(50, 2, 3); // `Buffer` 2

int offset0; TF_EXPECT_OK(planner.GetOffsetForBuffer(0, &offset0)); int offset1; TF_EXPECT_OK(planner.GetOffsetForBuffer(1, &offset1)); int offset2; TF_EXPECT_OK(planner.GetOffsetForBuffer(2, &offset2)); const int arena_size_needed = planner.GetMaximumMemorySize();

The goal is for applications to be able to experiment with different layout strategies without changing their client code, by swapping out classes that implement this interface.=

Source: `tensorflow/lite/micro/memory_planner/micro_memory_planner.h:45`

### tflite::MicroMemoryPlanner::MicroMemoryPlanner

`method` · `cpp`

```cpp
tflite::MicroMemoryPlanner::MicroMemoryPlanner()
```

Source: `tensorflow/lite/micro/memory_planner/micro_memory_planner.h:47`

### tflite::MicroMemoryPlanner::~MicroMemoryPlanner

`method` · `cpp`

```cpp
virtual tflite::MicroMemoryPlanner::~MicroMemoryPlanner()
```

Source: `tensorflow/lite/micro/memory_planner/micro_memory_planner.h:48`

### tflite::MicroMemoryPlanner::AddBuffer--classtflite_1_1MicroMemoryPlanner_1a8cd4f97494931f8c9757cdb621012faf

`method` · `cpp`

```cpp
virtual TfLiteStatus tflite::MicroMemoryPlanner::AddBuffer(int size, int first_time_used, int last_time_used) = 0
```

Pass information about a buffer's size and lifetime to the layout algorithm. The order this is called implicitly assigns an index to the result, so the buffer information that's passed into the N-th call of this method will be used as the buffer_index argument to `GetOffsetForBuffer()`.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| size | int | Required |  |
| first_time_used | int | Required |  |
| last_time_used | int | Required |  |

Source: `tensorflow/lite/micro/memory_planner/micro_memory_planner.h:55`

### tflite::MicroMemoryPlanner::AddBuffer--classtflite_1_1MicroMemoryPlanner_1a8b022e37bcc3d4357bf03d08c61c4d3d

`method` · `cpp`

```cpp
virtual TfLiteStatus tflite::MicroMemoryPlanner::AddBuffer(
    int size,
    int first_time_used,
    int last_time_used,
    int offline_offset
)
```

Record details of an offline planned buffer offset we want to place. offline_offset is the buffer offset from the start of the arena. This is to support offline memory planning from the flatbuffer metadata. By default, it returns an error.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| size | int | Required |  |
| first_time_used | int | Required |  |
| last_time_used | int | Required |  |
| offline_offset | int | Required |  |

Source: `tensorflow/lite/micro/memory_planner/micro_memory_planner.h:62`

### tflite::MicroMemoryPlanner::GetMaximumMemorySize

`method` · `cpp`

```cpp
virtual size_t tflite::MicroMemoryPlanner::GetMaximumMemorySize() = 0
```

The largest contiguous block of memory that's needed to hold the layout.

Source: `tensorflow/lite/micro/memory_planner/micro_memory_planner.h:68`

### tflite::MicroMemoryPlanner::GetBufferCount

`method` · `cpp`

```cpp
virtual int tflite::MicroMemoryPlanner::GetBufferCount() = 0
```

How many buffers have been added to the planner.

Source: `tensorflow/lite/micro/memory_planner/micro_memory_planner.h:70`

### tflite::MicroMemoryPlanner::GetOffsetForBuffer

`method` · `cpp`

```cpp
virtual TfLiteStatus tflite::MicroMemoryPlanner::GetOffsetForBuffer(int buffer_index, int *offset) = 0
```

Calculated layout offset for the N-th buffer added to the planner.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| buffer_index | int | Required |  |
| offset | int * | Required |  |

Source: `tensorflow/lite/micro/memory_planner/micro_memory_planner.h:72`

### tflite::MicroMemoryPlanner::Init

`method` · `cpp`

```cpp
virtual TfLiteStatus tflite::MicroMemoryPlanner::Init(unsigned char *scratch_buffer, int scratch_buffer_size)
```

Provides the scratch buffer in case that the memory planner needs it. The lifetime of scratch buffers lifetime lasts until the static memory plan is committed. The default implementation is for the memory planner that does not need scratch buffer and simply returns ok.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| scratch_buffer | unsigned char * | Required |  |
| scratch_buffer_size | int | Required |  |

Source: `tensorflow/lite/micro/memory_planner/micro_memory_planner.h:79`

### tflite::MicroMemoryPlanner::preserves_all_tensors

`method` · `cpp`

```cpp
virtual bool tflite::MicroMemoryPlanner::preserves_all_tensors() const = 0
```

Method will return True if the `MicroMemoryPlanner` preserves all tensors after invocation, and False if it doesn't.

Source: `tensorflow/lite/micro/memory_planner/micro_memory_planner.h:86`

### tflite::MicroMemoryPlanner::PrintMemoryPlan

`method` · `cpp`

```cpp
virtual void tflite::MicroMemoryPlanner::PrintMemoryPlan()
```

Source: `tensorflow/lite/micro/memory_planner/micro_memory_planner.h:88`
