src/oldpool.cpp
branchcustombridgeheads
changeset 5650 aefc131bf5ce
parent 5649 55c8267c933f
child 5860 7fdc9b423ba1
equal deleted inserted replaced
5649:55c8267c933f 5650:aefc131bf5ce
     3 #include "stdafx.h"
     3 #include "stdafx.h"
     4 #include "openttd.h"
     4 #include "openttd.h"
     5 #include "debug.h"
     5 #include "debug.h"
     6 #include "functions.h"
     6 #include "functions.h"
     7 #include "oldpool.h"
     7 #include "oldpool.h"
       
     8 #include "helpers.hpp"
     8 
     9 
     9 /**
    10 /**
    10  * Clean a pool in a safe way (does free all blocks)
    11  * Clean a pool in a safe way (does free all blocks)
    11  */
    12  */
    12 void CleanPool(OldMemoryPool *pool)
    13 void CleanPool(OldMemoryPool *pool)
    47 	pool->total_items = (pool->current_blocks + 1) * (1 << pool->block_size_bits);
    48 	pool->total_items = (pool->current_blocks + 1) * (1 << pool->block_size_bits);
    48 
    49 
    49 	DEBUG(misc, 4, "[Pool] (%s) increasing size of pool to %d items (%d bytes)", pool->name, pool->total_items, pool->total_items * pool->item_size);
    50 	DEBUG(misc, 4, "[Pool] (%s) increasing size of pool to %d items (%d bytes)", pool->name, pool->total_items, pool->total_items * pool->item_size);
    50 
    51 
    51 	/* Increase the poolsize */
    52 	/* Increase the poolsize */
    52 	pool->blocks = realloc(pool->blocks, sizeof(pool->blocks[0]) * (pool->current_blocks + 1));
    53 	ReallocT(&pool->blocks, pool->current_blocks + 1);
    53 	if (pool->blocks == NULL) error("Pool: (%s) could not allocate memory for blocks", pool->name);
    54 	if (pool->blocks == NULL) error("Pool: (%s) could not allocate memory for blocks", pool->name);
    54 
    55 
    55 	/* Allocate memory to the new block item */
    56 	/* Allocate memory to the new block item */
    56 	pool->blocks[pool->current_blocks] = malloc(pool->item_size * (1 << pool->block_size_bits));
    57 	MallocT(&pool->blocks[pool->current_blocks], pool->item_size * (1 << pool->block_size_bits));
    57 	if (pool->blocks[pool->current_blocks] == NULL)
    58 	if (pool->blocks[pool->current_blocks] == NULL)
    58 		error("Pool: (%s) could not allocate memory for blocks", pool->name);
    59 		error("Pool: (%s) could not allocate memory for blocks", pool->name);
    59 
    60 
    60 	/* Clean the content of the new block */
    61 	/* Clean the content of the new block */
    61 	memset(pool->blocks[pool->current_blocks], 0, pool->item_size * (1 << pool->block_size_bits));
    62 	memset(pool->blocks[pool->current_blocks], 0, pool->item_size * (1 << pool->block_size_bits));