<!-- Download Links -->
<!-- Article image -->
<!-- Add the rest of your HTML here -->
As you know,
delete operations take a lot of CPU
time. If you work with
servers, CPU time is important. If additional memory is added to the server, then
the servers' available memory size will grow in a linear fashion. However CPU's
don't behave the same (dual CPU's doesn't necessarily mean twice the speed of a
one CPU situation.)
So common server code has it's own efficient memory management system.
the one of them for me.
About The Implementation
CVMemPool is generic (template) class since I assumed the client would want a similar usage as
CVMemPool, you can code like it's a general pointer.
CObj* p = new CObj;
CVMemPool has it's own 'allocation table' implemented using a circular queue, so you can check if a pointer in a pool is valid using
You can also check how many objects are allocated in the pool using
CVMemPool has two template variable,
class objT and
DWORD _dwPoolSizeT = 1000.
_dwPoolSizeT is the size of the pool. You can reconfigure the pool size with this variable.
objT should not be important to you. If
objT is absent and you have a different class make the object as below.
template <DWORD _dwPoolSizeT = 1000>
class CObj1 : public CVMemPool<>
class CObj2 : public CVMemPool<>
As you know, when a compiler sees the last instancing code, the compiler will think c1 and c2 are the same template class layout and so it make only one virtual pool (because
CVMemPool<T,F>::ms_pMemPool is static.)
class CObj : public CVMemPool<CObj>
CObj* p = new CObj; CObj* p2 = new CObj;
delete p; delete p2;
P4 1.6GHz, 256MB ram, Windows 2000 Professional, release executable testing.
Two situations tested:
first, CObj is 1,000 bytes size and loop new and delete 10,000 , 20.000 ....
first, CObj is 10,000 bytes size and loop new and delete 10,000 , 20.000 ....
( n * 1,000 is wrong, n* 10,000 is right, sorry )
The Results are below.
I can't say that these results are exactly right, but I think
CVMemPool will be better than the default heap operation (
delete) on the server side, or on the client side for
In the second situation, I tested 6,000 or over, but I couldn't see the result on the 'Heap' because the program gave a fatal error - insufficient memory - surely,
CVMemPool works well and fast.
I hope it help you. Thanks a lot!
14 Aug 2002 - Initial revision