aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2007-01-08 20:42:41 +0000
committerlloyd <[email protected]>2007-01-08 20:42:41 +0000
commit0b1e07c3a16a789ecee37e2819f1740c509f7fa0 (patch)
treeb2a74fa561af6b54529a4f7964c8a336ed2afefb /src
parent0ccf1c63617d957fd7ddd1f9f5897e5a80d80c15 (diff)
Work around some strange Visual Studio bugs that popped up when compiling
mem_pool.cpp with debug enabled.
Diffstat (limited to 'src')
-rw-r--r--src/mem_pool.cpp36
1 files changed, 14 insertions, 22 deletions
diff --git a/src/mem_pool.cpp b/src/mem_pool.cpp
index 870365412..25bbd6d4e 100644
--- a/src/mem_pool.cpp
+++ b/src/mem_pool.cpp
@@ -34,19 +34,11 @@ u32bit choose_pref_size(u32bit provided)
/*************************************************
* Memory_Block Constructor *
*************************************************/
-Pooling_Allocator::Memory_Block::Memory_Block(void* buf, u32bit map_size,
- u32bit block_size)
+Pooling_Allocator::Memory_Block::Memory_Block(void* buf)
{
buffer = static_cast<byte*>(buf);
bitmap = 0;
- this->block_size = block_size;
-
- buffer_end = buffer + (block_size * BITMAP_SIZE);
-
- clear_mem(buffer, block_size * BITMAP_SIZE);
-
- if(map_size != BITMAP_SIZE)
- throw Invalid_Argument("Memory_Block: Bad bitmap size");
+ buffer_end = buffer + (BLOCK_SIZE * BITMAP_SIZE);
}
/*************************************************
@@ -66,7 +58,7 @@ bool Pooling_Allocator::Memory_Block::contains(void* ptr,
u32bit length) const throw()
{
return ((buffer <= ptr) &&
- (buffer_end >= (byte*)ptr + length * block_size));
+ (buffer_end >= (byte*)ptr + length * BLOCK_SIZE));
}
/*************************************************
@@ -106,7 +98,7 @@ byte* Pooling_Allocator::Memory_Block::alloc(u32bit n) throw()
return 0;
bitmap |= mask;
- return buffer + offset * block_size;
+ return buffer + offset * BLOCK_SIZE;
}
/*************************************************
@@ -114,9 +106,9 @@ byte* Pooling_Allocator::Memory_Block::alloc(u32bit n) throw()
*************************************************/
void Pooling_Allocator::Memory_Block::free(void* ptr, u32bit blocks) throw()
{
- clear_mem((byte*)ptr, blocks * block_size);
+ clear_mem((byte*)ptr, blocks * BLOCK_SIZE);
- const u32bit offset = ((byte*)ptr - buffer) / block_size;
+ const u32bit offset = ((byte*)ptr - buffer) / BLOCK_SIZE;
if(offset == 0 && blocks == BITMAP_SIZE)
bitmap = ~bitmap;
@@ -131,7 +123,7 @@ void Pooling_Allocator::Memory_Block::free(void* ptr, u32bit blocks) throw()
* Pooling_Allocator Constructor *
*************************************************/
Pooling_Allocator::Pooling_Allocator(u32bit p_size, bool) :
- PREF_SIZE(choose_pref_size(p_size)), BLOCK_SIZE(64)
+ PREF_SIZE(choose_pref_size(p_size))
{
mutex = global_state().get_mutex();
last_used = blocks.begin();
@@ -167,6 +159,7 @@ void Pooling_Allocator::destroy()
void* Pooling_Allocator::allocate(u32bit n)
{
const u32bit BITMAP_SIZE = Memory_Block::bitmap_size();
+ const u32bit BLOCK_SIZE = Memory_Block::block_size();
Mutex_Holder lock(mutex);
@@ -200,6 +193,7 @@ void* Pooling_Allocator::allocate(u32bit n)
void Pooling_Allocator::deallocate(void* ptr, u32bit n)
{
const u32bit BITMAP_SIZE = Memory_Block::bitmap_size();
+ const u32bit BLOCK_SIZE = Memory_Block::block_size();
if(ptr == 0 && n == 0)
return;
@@ -215,10 +209,10 @@ void Pooling_Allocator::deallocate(void* ptr, u32bit n)
std::vector<Memory_Block>::iterator i =
std::lower_bound(blocks.begin(), blocks.end(), ptr);
- if(i != blocks.end() && i->contains((byte*)ptr, block_no))
- i->free(ptr, block_no);
- else
+ if(i == blocks.end() || !i->contains(ptr, block_no))
throw Invalid_State("Pointer released to the wrong allocator");
+
+ i->free(ptr, block_no);
}
}
@@ -256,6 +250,7 @@ byte* Pooling_Allocator::allocate_blocks(u32bit n)
void Pooling_Allocator::get_more_core(u32bit in_bytes)
{
const u32bit BITMAP_SIZE = Memory_Block::bitmap_size();
+ const u32bit BLOCK_SIZE = Memory_Block::block_size();
const u32bit TOTAL_BLOCK_SIZE = BLOCK_SIZE * BITMAP_SIZE;
@@ -271,10 +266,7 @@ void Pooling_Allocator::get_more_core(u32bit in_bytes)
for(u32bit j = 0; j != in_blocks; ++j)
{
byte* byte_ptr = static_cast<byte*>(ptr);
-
- blocks.push_back(
- Memory_Block(byte_ptr + j * TOTAL_BLOCK_SIZE, BITMAP_SIZE, BLOCK_SIZE)
- );
+ blocks.push_back(Memory_Block(byte_ptr + j * TOTAL_BLOCK_SIZE));
}
std::sort(blocks.begin(), blocks.end());