���������������

������������

Memory Pool ������������������������������


���������programmer-13-memory-pool.pdf

���������: "Peng Chunhua" <chpeng@psh.com.cn>
������������: 2002���9���12��� AM 11:00
������: ������ [������������] ���������������������

To:���������

������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������2002���9������������������������������[������������]���������Memory Pool���������������������������������������������������������������������������������������������������������������������������Memory Pool���������������������������������������������[������������������������]���[������������������������]���������������������������������������������������

������������������������������
���������������C++������������������������������������������������������������������Cookie������������������������

������������������������������������������������VC6���C++Builder���������������������������������������������������������������������new������������������������malloc��� ������C++������������������������������������������malloc���������������������������������VC6.0���������������Debug��������������������������������������������������������������� ������32���������������������������������������������������������������������������������������������������������������������������������������VC6���������Debug��������������������������������� ������������������������malloc���Debug������������������������������������������������VC6.0���Release������������������������������������������malloc��������� ���������������HeapAlloc������������������������������HeapFree������VC���������������������������������������������������������������Release������malloc ������������������HeapAlloc������������Debug���malloc���������������HeapAlloc() + 0x20 ������������������������������������Release������������������������HeapSize���������������������VC������������������������������malloc, new���������������Heap������������������VC���������������������_crtheap���������������������������������10000000���C1������������VC���C++ Builder���������������������������������������������������������Release���������������������������������������32��������������������������������������������������������������� Cookie���C++���������������������������������������HeapAlloc������������������������������32������������������������������������������32������������������������������������ ���������������������������

���C++Builder������������������VC���������������������C++Buider���������Heap������������������������������������������TMemoryManager������ ������������������������������������VirtualAlloc������������16KByte������������������������malloc������������������C++Builder��������������������� ���������������������������������������������������������������������������������������������������������������������VirtualAlloc���������������������������C++Builder������ ���������������������������������������������������������C++Builder���������������

���������������������
���������������VC6.0���C++Builder���������������������������������������������������������VC���C++Builder���������������������������������VC������������������ ���������������������������_crtheap������������������������������������������VC������������������Heap������������Heap���������������������C++Builder������������ ���������������������VirtualAlloc���������������VirtualAlloc���������������������������������VirtualAlloc������������������������������������ VirtualAlloc���������������malloc���������������������������������������������������VC������������������������VirtualAlloc���������������������m��� malloc���������������������������n*m������������������������������������������������������
VC = n*m
C++Builder=n+m
���������������������������C++Builder������������������������VirtualAlloc���������������16K(0x4000)������������������������������1000000 ���������������������������������������(������,���������������������)���������������C++Builder������������������������������������������������������C++Builder������������ ���������������������������������������������������������TaskManager���������������������������������������������������������������������������VirtualAlloc��������������� ������������������������������������������������������������C++Builder���������������������������������������������

������GCC������������������������������������������������������������

E-mail:chpeng@psh.com.cn

���������������

��������������������������������������������������������������������������������������������������������� "������������" ������������������

���������������������������������������������������������������������������������������������������������������������������VC���BCB������������������������������������VC ������������ HeapAlloc()���������������������������������������������������������������blocks���������HeapAlloc()��������������� memory pool������Windows30/31/95 ������ ��������������������������������������������������������������������� platform-specific ������������������������

������������������������������������������ VC malloc debug/release ������������������������������������������������������������������������������ Doug Lea ��� malloc() ������������������������������������������

��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� "������������" ������������������������������������������������������

������������: 2002���9���16��� PM 02:08

������������������������������Memory Pool���������������Memory Pool���������������������������

������������������������HeapAlloc������������������������������������������������������������������������������������
���������������������������������Memory Pool������������������������������������Memory Pool���������������������
������������

������Memoey Pool������������������������������
1���Memory Pool������������������������������������������������������������������������������������������
2���Memory pool������������������������������������Memory Pool���������������������������
3���Memory pool���������������new,delete������������������������������������������������������������������������������new���������������������delete���������������������������������������������Memory pool������������������������������������������������������������

4���������VC6.0���������Memory pool���������Debug���������������VC6.0���������������������������������
5������������BoundsChecker���������������������������������(Memory Leak)������������������������������������������������������������������������������

������������������������������������������������������������������������VC6���allocator���new���������������������������������������������Bug��������������������������������������������������������������������������������� 9���

MyAlloc.allocate(size, (int*)0);���������������������size*sizeof(int*)=64���������
���������new C1���������������������������16������������������������������������������������������������������������������������������������������������������CB5������new���������������������6S������������ ������������������������������������������29S������������������6S���������������������������������������������������������CPU���OS���Memory������������

���������������������������������������������������������������������

������������������


������������: 2002���9���25��� PM 03:22

���������������������������������STL���������������������������������������������������������������������

������__default_alloc_template���������������������������������������������������128bytes������������������������������������������������������������128bytes���������������

���������������������������������free list������������������������������������������������������

������������������������������������������������������������������������
static void* allocate(size_t __n)
{
........
else {
  _Obj* __STL_VOLATILE* __my_free_list
    = _S_free_list + _S_freelist_index(__n);
........
  _Obj* __RESTRICT __result = *__my_free_list;
  if (__result == 0)
    __ret = _S_refill(_S_round_up(__n));
  else {
    *__my_free_list = __result -> _M_free_list_link;
    __ret = __result;
  }
}
}

���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
���������__default_alloc_template���������������������������deconstructor���������������������������������������������������������������������������������������������������������

���������������������������SGI���bug������
������������

��������������������������� bug������������������������

memory pool ������������������ blocks��������������������������������������������������� memory leak���
������������������������������������������������������blocks��������� SGI allocator ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ PDF������������������

��������������������������������������������� pool���������������������modern OS ������������������������������������������ process���