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

マクロ定義

#define X__IS_VALID_RANGE(x)   (x_is_within_ptr(x, self->top, self->top + 1 + (self->block_size * (self->num_blocks - 1))))
 

関数

static void X__MakeBlocks (XFixedAllocator *self)
 
void * xfalloc_allocate (XFixedAllocator *self)
 
void xfalloc_clear (XFixedAllocator *self)
 
void xfalloc_deallocate (XFixedAllocator *self, void *ptr)
 
void xfalloc_init (XFixedAllocator *self, void *heap, size_t heap_size, size_t block_size)
 

詳解

著者
MaskedW

関数詳解

void* xfalloc_allocate ( XFixedAllocator self)

ヒープから1ブロックを取り出して返します

void xfalloc_clear ( XFixedAllocator self)

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

void xfalloc_deallocate ( XFixedAllocator self,
void *  ptr 
)

ヒープにブロックを返却します

ptrがNULLの時は何もしません。

void xfalloc_init ( XFixedAllocator self,
void *  heap,
size_t  heap_size,
size_t  block_size 
)

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

引数
heapブロック化するメモリ領域
heap_sizeheap領域のバイト数
block_size1ブロックのサイズ
alignmentブロックのアラインメント
事前条件
  • heap != NULL
  • heap_size > 0
  • block_size > 0
注意
heapが指すアドレスと、block_sizeはsizeof(void*)のアライメントに切り上げられ ます。その結果、意図したブロック分けができていない場合がありますので、はじめ からアラインメントを意識した引数を用意するか初期化後に、必要量を満たせている か確認した方がよいでしょう。