Remove FX_NEW_VECTOR() macros.
[pdfium.git] / core / include / fxcrt / fx_memory.h
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #ifndef _FX_MEMORY_H_
8 #define _FX_MEMORY_H_
9
10 #include "fx_system.h"
11
12 #ifdef __cplusplus
13 #include <new>
14 extern "C" {
15 #endif
16 #define FX_Alloc(type, size)                                            (type*)calloc(size, sizeof(type))
17 #define FX_Realloc(type, ptr, size)                                     (type*)realloc(ptr, sizeof(type) * (size))
18 #define FX_AllocNL(type, size)                                          FX_Alloc(type, size)
19 #define FX_ReallocNL(type, ptr, size)                           FX_Realloc(type, ptr, size)
20 #define FX_Free(ptr)                                                            free(ptr)
21 void*   FXMEM_DefaultAlloc(size_t byte_size, int flags);
22 void*   FXMEM_DefaultRealloc(void* pointer, size_t new_size, int flags);
23 void    FXMEM_DefaultFree(void* pointer, int flags);
24 #ifdef __cplusplus
25 }
26
27 class CFX_DestructObject 
28 {
29 public:
30
31     virtual ~CFX_DestructObject() {}
32 };
33 class CFX_GrowOnlyPool 
34 {
35 public:
36
37     CFX_GrowOnlyPool(size_t trunk_size = 16384);
38
39     ~CFX_GrowOnlyPool();
40
41     void        SetTrunkSize(size_t trunk_size)
42     {
43         m_TrunkSize = trunk_size;
44     }
45
46     void*       AllocDebug(size_t size, FX_LPCSTR file, int line)
47     {
48         return Alloc(size);
49     }
50
51     void*       Alloc(size_t size);
52
53     void*       ReallocDebug(void* p, size_t new_size, FX_LPCSTR file, int line)
54     {
55         return NULL;
56     }
57
58     void*       Realloc(void* p, size_t new_size)
59     {
60         return NULL;
61     }
62
63     void        Free(void*) {}
64
65     void        FreeAll();
66 private:
67
68     size_t      m_TrunkSize;
69
70     void*       m_pFirstTrunk;
71 };
72 #endif
73 #endif