Files
@ r7463:838c9d05e229
Branch filter:
Location: cpp/openttd-patchpack/source/src/oldpool.cpp - annotation
r7463:838c9d05e229
2.4 KiB
text/x-c
(svn r10964) -Update: WebTranslator2 update to 2007-08-22 22:57:00
croatian - 9 fixed, 13 changed by knovak (22)
italian - 10 fixed by lorenzodv (10)
japanese - 5 fixed by ickoonite (5)
polish - 10 fixed, 1 changed by meush (11)
slovak - 77 changed by lengyel (77)
spanish - 5 fixed by eusebio (5)
croatian - 9 fixed, 13 changed by knovak (22)
italian - 10 fixed by lorenzodv (10)
japanese - 5 fixed by ickoonite (5)
polish - 10 fixed, 1 changed by meush (11)
slovak - 77 changed by lengyel (77)
spanish - 5 fixed by eusebio (5)
r5584:545d748cc681 r5584:545d748cc681 r6351:0ad6f06c84a9 r6351:0ad6f06c84a9 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5587:034e5e185dc2 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r7375:6e8d6e5fb07f r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r7375:6e8d6e5fb07f r5584:545d748cc681 r7413:3ccdde9800e0 r5584:545d748cc681 r7375:6e8d6e5fb07f r7375:6e8d6e5fb07f r7375:6e8d6e5fb07f r5584:545d748cc681 r7375:6e8d6e5fb07f r5584:545d748cc681 r7413:3ccdde9800e0 r5584:545d748cc681 r5584:545d748cc681 r7375:6e8d6e5fb07f r5584:545d748cc681 r5584:545d748cc681 r7375:6e8d6e5fb07f r7375:6e8d6e5fb07f r7375:6e8d6e5fb07f r7378:2aebcfdbd3c3 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r7375:6e8d6e5fb07f r5584:545d748cc681 r5584:545d748cc681 r7375:6e8d6e5fb07f r5584:545d748cc681 r7375:6e8d6e5fb07f r5584:545d748cc681 r7375:6e8d6e5fb07f r5584:545d748cc681 r5584:545d748cc681 r7375:6e8d6e5fb07f r7375:6e8d6e5fb07f r5584:545d748cc681 r5584:545d748cc681 r7375:6e8d6e5fb07f r7375:6e8d6e5fb07f r7375:6e8d6e5fb07f r5584:545d748cc681 r5584:545d748cc681 r7375:6e8d6e5fb07f r5584:545d748cc681 r5584:545d748cc681 r7375:6e8d6e5fb07f r5584:545d748cc681 r5584:545d748cc681 r7375:6e8d6e5fb07f r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r7375:6e8d6e5fb07f r5584:545d748cc681 r7375:6e8d6e5fb07f r7375:6e8d6e5fb07f r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 | /* $Id$ */
/** @file oldpool.cpp */
#include "stdafx.h"
#include "openttd.h"
#include "debug.h"
#include "functions.h"
#include "oldpool.h"
#include "helpers.hpp"
/**
* Clean a pool in a safe way (does free all blocks)
*/
void OldMemoryPoolBase::CleanPool()
{
uint i;
DEBUG(misc, 4, "[Pool] (%s) cleaning pool..", this->name);
this->cleaning_pool = true;
/* Free all blocks */
for (i = 0; i < this->current_blocks; i++) {
if (this->clean_block_proc != NULL) {
this->clean_block_proc(i * (1 << this->block_size_bits), (i + 1) * (1 << this->block_size_bits) - 1);
}
free(this->blocks[i]);
}
this->cleaning_pool = false;
/* Free the block itself */
free(this->blocks);
/* Clear up some critical data */
this->total_items = 0;
this->current_blocks = 0;
this->blocks = NULL;
this->first_free_index = 0;
}
/**
* This function tries to increase the size of array by adding
* 1 block too it
*
* @return Returns false if the pool could not be increased
*/
bool OldMemoryPoolBase::AddBlockToPool()
{
/* Is the pool at his max? */
if (this->max_blocks == this->current_blocks) return false;
this->total_items = (this->current_blocks + 1) * (1 << this->block_size_bits);
DEBUG(misc, 4, "[Pool] (%s) increasing size of pool to %d items (%d bytes)", this->name, this->total_items, this->total_items * this->item_size);
/* Increase the poolsize */
this->blocks = ReallocT(this->blocks, this->current_blocks + 1);
if (this->blocks == NULL) error("Pool: (%s) could not allocate memory for blocks", this->name);
/* Allocate memory to the new block item */
this->blocks[this->current_blocks] = MallocT<byte>(this->item_size * (1 << this->block_size_bits));
if (this->blocks[this->current_blocks] == NULL)
error("Pool: (%s) could not allocate memory for blocks", this->name);
/* Clean the content of the new block */
memset(this->blocks[this->current_blocks], 0, this->item_size * (1 << this->block_size_bits));
/* Call a custom function if defined (e.g. to fill indexes) */
if (this->new_block_proc != NULL) this->new_block_proc(this->current_blocks * (1 << this->block_size_bits));
/* We have a new block */
this->current_blocks++;
return true;
}
/**
* Adds blocks to the pool if needed (and possible) till index fits inside the pool
*
* @return Returns false if adding failed
*/
bool OldMemoryPoolBase::AddBlockIfNeeded(uint index)
{
while (index >= this->total_items) {
if (!this->AddBlockToPool()) return false;
}
return true;
}
|