static void * wmem_block_fast_alloc(void *private_data, const size_t size) { wmem_block_fast_allocator_t *allocator = (wmem_block_fast_allocator_t*) private_data; wmem_block_fast_chunk_t *chunk; gint32 real_size; g_assert(size <= WMEM_BLOCK_MAX_ALLOC_SIZE); real_size = (gint32)(WMEM_ALIGN_SIZE(size) + WMEM_CHUNK_HEADER_SIZE); /* Allocate a new block if necessary. */ if (!allocator->block_list || (WMEM_BLOCK_SIZE - allocator->block_list->pos) < real_size) { wmem_block_fast_new_block(allocator); } chunk = (wmem_block_fast_chunk_t *) ((guint8 *) allocator->block_list + allocator->block_list->pos); /* safe to cast, size smaller than WMEM_BLOCK_MAX_ALLOC_SIZE */ chunk->len = (guint32) size; allocator->block_list->pos += real_size; /* and return the user's pointer */ return WMEM_CHUNK_TO_DATA(chunk); }
static void * wmem_block_fast_alloc(void *private_data, const size_t size) { wmem_block_fast_allocator_t *allocator = (wmem_block_fast_allocator_t*) private_data; wmem_block_fast_chunk_t *chunk; gint32 real_size; if (size > WMEM_BLOCK_MAX_ALLOC_SIZE) { wmem_block_fast_jumbo_t *block; /* allocate/initialize a new block of the necessary size */ block = (wmem_block_fast_jumbo_t *)wmem_alloc(NULL, size + WMEM_JUMBO_HEADER_SIZE + WMEM_CHUNK_HEADER_SIZE); block->next = allocator->jumbo_list; block->prev = NULL; allocator->jumbo_list = block; chunk = ((wmem_block_fast_chunk_t*)((guint8*)(block) + WMEM_JUMBO_HEADER_SIZE)); chunk->len = JUMBO_MAGIC; return WMEM_CHUNK_TO_DATA(chunk); } real_size = (gint32)(WMEM_ALIGN_SIZE(size) + WMEM_CHUNK_HEADER_SIZE); /* Allocate a new block if necessary. */ if (!allocator->block_list || (WMEM_BLOCK_SIZE - allocator->block_list->pos) < real_size) { wmem_block_fast_new_block(allocator); } chunk = (wmem_block_fast_chunk_t *) ((guint8 *) allocator->block_list + allocator->block_list->pos); /* safe to cast, size smaller than WMEM_BLOCK_MAX_ALLOC_SIZE */ chunk->len = (guint32) size; allocator->block_list->pos += real_size; /* and return the user's pointer */ return WMEM_CHUNK_TO_DATA(chunk); }