42 #include "utils/wrap_stdint.h" 99 return *
reinterpret_cast<const uint16_t *
>(
reinterpret_cast<const uint8_t *
>(
this) +
sizeof(mSize) + mSize);
111 *
reinterpret_cast<uint16_t *
>(
reinterpret_cast<uint8_t *
>(
this) +
sizeof(mSize) + mSize) = aNext;
131 return *(&mSize - 1);
153 return mSize != kGuardBlockSize &&
GetNext() != 0;
159 kGuardBlockSize = 0xffff,
169 uint8_t mMemory[
sizeof(uint16_t)];
206 void *CAlloc(
size_t aCount,
size_t aSize);
214 void Free(
void *aPointer);
221 const Block &super = BlockSuper();
222 const Block &first = BlockRight(super);
223 return super.
GetNext() == BlockOffset(first) && first.
GetSize() == kFirstBlockSize;
231 return kFirstBlockSize;
237 #if OPENTHREAD_ENABLE_DTLS 242 kAlignSize =
sizeof(long),
243 kBlockRemainderSize = kAlignSize -
sizeof(uint16_t) * 2,
244 kSuperBlockSize = kAlignSize -
sizeof(
Block),
245 kFirstBlockSize = kMemorySize - kAlignSize * 3 +
247 kSuperBlockOffset = kAlignSize -
sizeof(uint16_t),
248 kFirstBlockOffset = kAlignSize * 2 -
sizeof(uint16_t),
249 kGuardBlockOffset = kMemorySize -
sizeof(uint16_t),
260 Block &BlockAt(uint16_t aOffset) {
261 return *
reinterpret_cast<Block *
>(&mMemory.m16[aOffset / 2]);
272 Block &BlockOf(
void *aPointer) {
273 uint16_t offset =
static_cast<uint16_t
>(
reinterpret_cast<uint8_t *
>(aPointer) - mMemory.m8);
274 offset -=
sizeof(uint16_t);
275 return BlockAt(offset);
284 Block &BlockSuper(
void) {
285 return BlockAt(kSuperBlockOffset);
297 return BlockAt(aBlock.
GetNext());
309 return BlockAt(BlockOffset(aBlock) +
sizeof(
Block) + aBlock.
GetSize());
327 return (BlockOffset(aBlock) != kFirstBlockOffset && aBlock.
IsLeftFree());
338 uint16_t BlockOffset(
const Block &aBlock) {
339 return static_cast<uint16_t
>(
reinterpret_cast<const uint8_t *
>(&aBlock) - mMemory.m8);
351 void BlockInsert(
Block &aPrev,
Block &aBlock);
356 long mLong[kMemorySize /
sizeof(long)];
357 uint8_t m8[kMemorySize];
358 uint16_t m16[kMemorySize /
sizeof(uint16_t)];
365 #endif // OT_HEAP_HPP_
This class defines functionality to manipulate heap.
Definition: heap.hpp:186
void SetNext(uint16_t aNext)
This method updates the offset of the free block after this block.
Definition: heap.hpp:110
#define OPENTHREAD_CONFIG_MBEDTLS_HEAP_SIZE
The size of mbedTLS heap buffer when DTLS is enabled.
Definition: openthread-core-default-config.h:862
void * GetPointer(void)
This method returns the pointer to the start of the memory for user.
Definition: heap.hpp:120
uint16_t GetLeftNext(void) const
This method returns the offset of the free block after the left neighbor block.
Definition: heap.hpp:130
uint16_t GetNext(void) const
This method returns the offset of the free block after this block.
Definition: heap.hpp:98
uint16_t GetSize(void) const
This method returns the size of this block.
Definition: heap.hpp:74
bool IsClean(void)
This method returns whether the heap is clean.
Definition: heap.hpp:220
bool IsLeftFree(void) const
This method returns whether the left neighbor block is a free block.
Definition: heap.hpp:141
#define OPENTHREAD_CONFIG_MBEDTLS_HEAP_SIZE_NO_DTLS
The size of mbedTLS heap buffer when DTLS is disabled.
Definition: openthread-core-default-config.h:872
This class represents a memory block.
Definition: heap.hpp:63
void SetSize(uint16_t aSize)
This method updates the size of this block.
Definition: heap.hpp:84
bool IsFree(void) const
This method returns whether the current block is a free block.
Definition: heap.hpp:152
This file includes compile-time configuration constants for OpenThread.
size_t GetCapacity(void) const
This method returns the capacity of this heap.
Definition: heap.hpp:230