static void * wmem_block_fast_realloc(void *private_data, void *ptr, const size_t size) { wmem_block_fast_chunk_t *chunk; chunk = WMEM_DATA_TO_CHUNK(ptr); /* grow */ if (chunk->len < size) { void *newptr; /* need to alloc and copy; free is no-op, so don't call it */ newptr = wmem_block_fast_alloc(private_data, size); memcpy(newptr, ptr, chunk->len); return newptr; } /* shrink or same space - great we can do nothing */ return ptr; }
static void * wmem_block_fast_realloc(void *private_data, void *ptr, const size_t size) { wmem_block_fast_chunk_t *chunk; chunk = WMEM_DATA_TO_CHUNK(ptr); if (chunk->len == JUMBO_MAGIC) { wmem_block_fast_jumbo_t *block; block = ((wmem_block_fast_jumbo_t*)((guint8*)(chunk) - WMEM_JUMBO_HEADER_SIZE)); block = (wmem_block_fast_jumbo_t*)wmem_realloc(NULL, block, size + WMEM_JUMBO_HEADER_SIZE + WMEM_CHUNK_HEADER_SIZE); if (block->prev) { block->prev->next = block; } else { wmem_block_fast_allocator_t *allocator = (wmem_block_fast_allocator_t*) private_data; allocator->jumbo_list = block; } if (block->next) { block->next->prev = block; } return ((void*)((guint8*)(block) + WMEM_JUMBO_HEADER_SIZE + WMEM_CHUNK_HEADER_SIZE)); } else if (chunk->len < size) { /* grow */ void *newptr; /* need to alloc and copy; free is no-op, so don't call it */ newptr = wmem_block_fast_alloc(private_data, size); memcpy(newptr, ptr, chunk->len); return newptr; } /* shrink or same space - great we can do nothing */ return ptr; }