oldpool.cpp
Go to the documentation of this file.00001
00002
00005 #include "stdafx.h"
00006 #include "debug.h"
00007 #include "oldpool.h"
00008 #include "core/alloc_func.hpp"
00009
00013 void OldMemoryPoolBase::CleanPool()
00014 {
00015 uint i;
00016
00017 DEBUG(misc, 4, "[Pool] (%s) cleaning pool..", this->name);
00018
00019 this->cleaning_pool = true;
00020
00021 for (i = 0; i < this->current_blocks; i++) {
00022 if (this->clean_block_proc != NULL) {
00023 this->clean_block_proc(i * (1 << this->block_size_bits), (i + 1) * (1 << this->block_size_bits) - 1);
00024 }
00025 free(this->blocks[i]);
00026 }
00027 this->cleaning_pool = false;
00028
00029
00030 free(this->blocks);
00031
00032
00033 this->total_items = 0;
00034 this->current_blocks = 0;
00035 this->blocks = NULL;
00036 this->first_free_index = 0;
00037 }
00038
00045 bool OldMemoryPoolBase::AddBlockToPool()
00046 {
00047
00048 if (this->max_blocks == this->current_blocks) return false;
00049
00050 this->total_items = (this->current_blocks + 1) * (1 << this->block_size_bits);
00051
00052 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);
00053
00054
00055 this->blocks = ReallocT(this->blocks, this->current_blocks + 1);
00056
00057
00058 this->blocks[this->current_blocks] = MallocT<byte>(this->item_size * (1 << this->block_size_bits));
00059
00060
00061 memset(this->blocks[this->current_blocks], 0, this->item_size * (1 << this->block_size_bits));
00062
00063
00064 if (this->new_block_proc != NULL) this->new_block_proc(this->current_blocks * (1 << this->block_size_bits));
00065
00066
00067 this->current_blocks++;
00068
00069 return true;
00070 }
00071
00077 bool OldMemoryPoolBase::AddBlockIfNeeded(uint index)
00078 {
00079 while (index >= this->total_items) {
00080 if (!this->AddBlockToPool()) return false;
00081 }
00082
00083 return true;
00084 }