| Flutter Impeller |

Public Member Functions | Static Public Member Functions | List of all members
impeller::Allocation Class Reference

Describes an allocation on the heap. More...

`#include <allocation.h>`

## Public Member Functions
| Allocation ()
| Constructs a new zero-sized allocation. More...
| ~Allocation ()
| Destroys the allocation. More...
uint8_t * | GetBuffer () const
| Gets the pointer to the start of the allocation. More...
Bytes | GetLength () const
| Gets the length of the allocation. More...
Bytes | GetReservedLength () const
| Gets the reserved length of the allocation. Calls to truncate may be ignored till the length exceeds the reserved length. More...
bool | Truncate (Bytes length, bool npot=true)
| Resize the underlying allocation to at least given number of bytes. More...

## Static Public Member Functions
static uint32_t | NextPowerOfTwoSize (uint32_t x)
| Gets the next power of two size. More...

## Detailed Description

Describes an allocation on the heap.

            Managing allocations through this utility makes it harder to
            miss allocation failures.

Definition at line 22 of file allocation.h.

## Constructor & Destructor Documentation

## ◆ Allocation()

impeller::Allocation::Allocation | ( |  | ) |
| default

Constructs a new zero-sized allocation.

## ◆ ~Allocation()

impeller::Allocation::~Allocation | ( |  | ) |

Destroys the allocation.

Definition at line 16 of file allocation.cc.

16 {
17 ::free(buffer_);
18 }

## Member Function Documentation

## ◆ GetBuffer()

uint8_t * impeller::Allocation::GetBuffer | ( |  | ) | const

Gets the pointer to the start of the allocation.

            This pointer is only valid till the next call to `Truncate`.

Returns
  The pointer to the start of the allocation.

Definition at line 20 of file allocation.cc.

20 {
21 return buffer_;
22 }

Referenced by impeller::ProcTableGLES::GetProgramInfoLogString(), and impeller::interop::testing::TEST_P().

## ◆ GetLength()

Bytes impeller::Allocation::GetLength | ( |  | ) | const

Gets the length of the allocation.

Returns
  The length.

Definition at line 24 of file allocation.cc.

24 {
25 return length_;
26 }

## ◆ GetReservedLength()

Bytes impeller::Allocation::GetReservedLength | ( |  | ) | const

Gets the reserved length of the allocation. Calls to truncate may be ignored till the length exceeds the reserved length.

Returns
  The reserved length.

Definition at line 28 of file allocation.cc.

28 {
29 return reserved_;
30 }

## ◆ NextPowerOfTwoSize()

uint32_t impeller::Allocation::NextPowerOfTwoSize | ( | uint32_t | x | ) |
| static

Gets the next power of two size.

Parameters

  [in] | x | The size.

Returns
  The next power of two of x.

Definition at line 41 of file allocation.cc.

41 {
42 if (x == 0) {
43 return 1;
44 }
45
46 --x;
47
48 x |= x >> 1;
49 x |= x >> 2;
50 x |= x >> 4;
51 x |= x >> 8;
52 x |= x >> 16;
53
54 return x + 1;
55 }
x
int32_t x
Definition: dl_golden_unittests.cc:458

References x.

## ◆ Truncate()

bool impeller::Allocation::Truncate | ( | Bytes | length,
|  | bool | npot = `true`
| ) |  |

Resize the underlying allocation to at least given number of bytes.

In case of failure, false is returned and the underlying allocation remains unchanged.

Warning
  Pointers to buffers obtained via previous calls to `GetBuffer` may become invalid at this point.

Parameters

  [in] | length | The length.
  [in] | npot | Whether to round up the length to the next power of two.

Returns
  If the underlying allocation was resized to the new size.

Definition at line 32 of file allocation.cc.

32 {
33 const auto reserved = npot ? ReserveNPOT(length) : Reserve(length);
34 if (!reserved) {
35 return false;
36 }
37 length_ = length;
38 return true;
39 }

Referenced by impeller::ProcTableGLES::GetProgramInfoLogString(), and impeller::interop::testing::TEST_P().

The documentation for this class was generated from the following files:

- impeller/base/allocation.h
- impeller/base/allocation.cc