picox  0.1
xstack_allocator.c ファイル
xstack_allocator.c の依存先関係図:

関数

static uint8_t * X__GetBeginOrigin (XStackAllocator *self)
 
static bool X__IsValidRange (XStackAllocator *self, const void *p)
 
void * xsalloc_allocate (XStackAllocator *self, size_t size)
 
void xsalloc_clear (XStackAllocator *self)
 
void xsalloc_init (XStackAllocator *self, void *heap, size_t size, size_t alignment)
 
void xsalloc_rewind (XStackAllocator *self, void *begin, void *end)
 

詳解

著者
MaskedW

関数詳解

void* xsalloc_allocate ( XStackAllocator self,
size_t  size 
)

ヒープからsizeバイトのメモリを切り出して返します

覚え書き
確保するメモリサイズはalignmentに切り上げられます。
void xsalloc_clear ( XStackAllocator self)

ヒープを初期状態に戻します

void xsalloc_init ( XStackAllocator self,
void *  heap,
size_t  size,
size_t  alignment 
)

メモリブロックを初期化します

引数
heapスタック管理するメモリ領域
sizeheap領域のサイズ
alignmentメモリ確保のアライメント
事前条件
  • heap != NULL
  • size >= alignment
  • alignment == 2のべき乗
覚え書き
heap領域はalignmentに切り上げられ、さらに、sizeは、alignmentに切り下げられま す。1バイトも無駄にしたくない場合は、heapをあらかじめアラインして確保し、 sizeはalignmentの倍数にしてください。
void xsalloc_rewind ( XStackAllocator self,
void *  begin,
void *  end 
)

begin, endの位置にスタックポインタを移動します

事前条件
  • end >= begin
  • begin, endはこのオブジェクトのheap領域を指していること。
  • begin, endはalignmentの倍数であること。