OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef _FX_MEMORY_H_ | 7 #ifndef _FX_MEMORY_H_ |
8 #define _FX_MEMORY_H_ | 8 #define _FX_MEMORY_H_ |
9 #ifndef _FX_SYSTEM_H_ | 9 #ifndef _FX_SYSTEM_H_ |
10 #include "fx_system.h" | 10 #include "fx_system.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 void operator delete[] (void* p) | 58 void operator delete[] (void* p) |
59 { | 59 { |
60 free(p); | 60 free(p); |
61 } | 61 } |
62 void* operator new (size_t, void* buf) | 62 void* operator new (size_t, void* buf) |
63 { | 63 { |
64 return buf; | 64 return buf; |
65 } | 65 } |
66 void operator delete (void*, void*)
{} | 66 void operator delete (void*, void*)
{} |
67 }; | 67 }; |
68 #endif | |
69 #ifdef __cplusplus | |
70 #if defined(_DEBUG) | 68 #if defined(_DEBUG) |
71 #define FX_NEW new(__FILE__, __LINE__) | 69 #define FX_NEW new(__FILE__, __LINE__) |
72 #else | 70 #else |
73 | |
74 #define FX_NEW new | 71 #define FX_NEW new |
75 #endif | 72 #endif |
76 #define FX_NEW_VECTOR(Pointer, Class, Count) \ | 73 #define FX_NEW_VECTOR(Pointer, Class, Count) \ |
77 { \ | 74 { \ |
78 Pointer = FX_Alloc(Class, Count); \ | 75 Pointer = FX_Alloc(Class, Count); \ |
79 if (Pointer) { \ | 76 if (Pointer) { \ |
80 for (int i = 0; i < (Count); i ++) new (Pointer + i) Class; \ | 77 for (int i = 0; i < (Count); i ++) new (Pointer + i) Class; \ |
81 } \ | 78 } \ |
82 } | 79 } |
83 #define FX_DELETE_VECTOR(Pointer, Class, Count) \ | 80 #define FX_DELETE_VECTOR(Pointer, Class, Count) \ |
84 { \ | 81 { \ |
85 for (int i = 0; i < (Count); i ++) Pointer[i].~Class(); \ | 82 for (int i = 0; i < (Count); i ++) Pointer[i].~Class(); \ |
86 FX_Free(Pointer); \ | 83 FX_Free(Pointer); \ |
87 } | 84 } |
88 class CFX_DestructObject : public CFX_Object | 85 class CFX_DestructObject : public CFX_Object |
89 { | 86 { |
90 public: | 87 public: |
91 | 88 |
92 virtual ~CFX_DestructObject() {} | 89 virtual ~CFX_DestructObject() {} |
93 }; | 90 }; |
94 class CFX_GrowOnlyPool : public CFX_Object | 91 #endif // __cplusplus |
95 { | 92 #endif // _FX_MEMORY_H_ |
96 public: | |
97 | |
98 CFX_GrowOnlyPool(size_t trunk_size = 16384); | |
99 | |
100 ~CFX_GrowOnlyPool(); | |
101 | |
102 void» SetTrunkSize(size_t trunk_size) | |
103 { | |
104 m_TrunkSize = trunk_size; | |
105 } | |
106 | |
107 void*» AllocDebug(size_t size, FX_LPCSTR file, int line) | |
108 { | |
109 return Alloc(size); | |
110 } | |
111 | |
112 void*» Alloc(size_t size); | |
113 | |
114 void*» ReallocDebug(void* p, size_t new_size, FX_LPCSTR file, int line) | |
115 { | |
116 return NULL; | |
117 } | |
118 | |
119 void*» Realloc(void* p, size_t new_size) | |
120 { | |
121 return NULL; | |
122 } | |
123 | |
124 void» Free(void*) {} | |
125 | |
126 void» FreeAll(); | |
127 private: | |
128 | |
129 size_t» m_TrunkSize; | |
130 | |
131 void*» m_pFirstTrunk; | |
132 }; | |
133 #endif | |
134 #endif | |
OLD | NEW |