picox
0.1
|
Stack memory allocator. [詳解]
#include <picox/core/xcore.h>
データ構造 | |
struct | XStackAllocator |
関数 | |
static size_t | xsalloc_alignment (const XStackAllocator *self) |
void * | xsalloc_allocate (XStackAllocator *self, size_t size) |
static uint8_t * | xsalloc_bedin (const XStackAllocator *self) |
static size_t | xsalloc_capacity (const XStackAllocator *self) |
void | xsalloc_clear (XStackAllocator *self) |
static uint8_t * | xsalloc_end (const XStackAllocator *self) |
static bool | xsalloc_growth_direction (XStackAllocator *self) |
static uint8_t * | xsalloc_heap (const XStackAllocator *self) |
void | xsalloc_init (XStackAllocator *self, void *heap, size_t size, size_t alignment) |
static size_t | xsalloc_reserve (const XStackAllocator *self) |
void | xsalloc_rewind (XStackAllocator *self, void *begin, void *end) |
static void | xsalloc_set_growth_direction (XStackAllocator *self, bool growth_upward) |
Stack memory allocator.
ヒープ領域をスタックの用にポインタをずらしながらメモリアロケーションを行い ます。 通常のmallocを使用した場合との主な違いは以下の通りです。
[利点]
ポインタをずらすだけなので超高速です。
個別の解放ができないのでヘッダ領域を使用しません。
個別の解放ができないので断片化しようがありません。
[欠点]
常に直線的にポインタ位置が移動するだけなので、個別にメモリの解放をするとい う概念がありません。
[利用例]
ゲームの1フレーム用スクラッチメモリ
|
inlinestatic |
初期化時に指定したアラインメントを返します
void* xsalloc_allocate | ( | XStackAllocator * | self, |
size_t | size | ||
) |
ヒープからsizeバイトのメモリを切り出して返します
|
inlinestatic |
先頭スタックポインタを返します
|
inlinestatic |
ヒープのサイズを返します
void xsalloc_clear | ( | XStackAllocator * | self | ) |
ヒープを初期状態に戻します
|
inlinestatic |
終端スタックポインタを返します
|
inlinestatic |
スタック伸長方向を返します
|
inlinestatic |
ヒープメモリを返します
void xsalloc_init | ( | XStackAllocator * | self, |
void * | heap, | ||
size_t | size, | ||
size_t | alignment | ||
) |
メモリブロックを初期化します
heap | スタック管理するメモリ領域 |
size | heap領域のサイズ |
alignment | メモリ確保のアライメント |
|
inlinestatic |
空きメモリバイト数を返します
void xsalloc_rewind | ( | XStackAllocator * | self, |
void * | begin, | ||
void * | end | ||
) |
begin, endの位置にスタックポインタを移動します
|
inlinestatic |
スタック伸長方向を設定します