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 CORE_INCLUDE_FXCRT_FX_MEMORY_H_ | 7 #ifndef CORE_INCLUDE_FXCRT_FX_MEMORY_H_ |
8 #define CORE_INCLUDE_FXCRT_FX_MEMORY_H_ | 8 #define CORE_INCLUDE_FXCRT_FX_MEMORY_H_ |
9 | 9 |
10 #include "core/include/fxcrt/fx_system.h" | 10 #include "core/include/fxcrt/fx_system.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 } | 62 } |
63 | 63 |
64 // Never returns NULL. | 64 // Never returns NULL. |
65 #define FX_Alloc(type, size) (type*) FX_AllocOrDie(size, sizeof(type)) | 65 #define FX_Alloc(type, size) (type*) FX_AllocOrDie(size, sizeof(type)) |
66 #define FX_Alloc2D(type, w, h) (type*) FX_AllocOrDie2D(w, h, sizeof(type)) | 66 #define FX_Alloc2D(type, w, h) (type*) FX_AllocOrDie2D(w, h, sizeof(type)) |
67 #define FX_Realloc(type, ptr, size) \ | 67 #define FX_Realloc(type, ptr, size) \ |
68 (type*) FX_ReallocOrDie(ptr, size, sizeof(type)) | 68 (type*) FX_ReallocOrDie(ptr, size, sizeof(type)) |
69 | 69 |
70 // May return NULL. | 70 // May return NULL. |
71 #define FX_TryAlloc(type, size) (type*) calloc(size, sizeof(type)) | 71 #define FX_TryAlloc(type, size) (type*) calloc(size, sizeof(type)) |
72 #define FX_TryRealloc(type, ptr, size) \ | |
Tom Sepez
2016/03/02 20:28:07
Hate to say this, but I might be willing to keep t
dsinclair
2016/03/02 20:55:36
Done.
| |
73 (type*) FX_SafeRealloc(ptr, size, sizeof(type)) | |
74 | |
75 #define FX_Free(ptr) free(ptr) | 72 #define FX_Free(ptr) free(ptr) |
76 | 73 |
77 class CFX_DestructObject { | 74 class CFX_DestructObject { |
78 public: | 75 public: |
79 virtual ~CFX_DestructObject() {} | 76 virtual ~CFX_DestructObject() {} |
80 }; | 77 }; |
81 class CFX_GrowOnlyPool { | |
82 public: | |
83 CFX_GrowOnlyPool(size_t trunk_size = 16384); | |
84 | 78 |
85 ~CFX_GrowOnlyPool(); | |
86 | |
87 void SetTrunkSize(size_t trunk_size) { m_TrunkSize = trunk_size; } | |
88 | |
89 void* AllocDebug(size_t size, const FX_CHAR* file, int line) { | |
90 return Alloc(size); | |
91 } | |
92 | |
93 void* Alloc(size_t size); | |
94 | |
95 void* ReallocDebug(void* p, size_t new_size, const FX_CHAR* file, int line) { | |
96 return NULL; | |
97 } | |
98 | |
99 void* Realloc(void* p, size_t new_size) { return NULL; } | |
100 | |
101 void Free(void* mem) {} | |
102 | |
103 void FreeAll(); | |
104 | |
105 private: | |
106 size_t m_TrunkSize; | |
107 | |
108 void* m_pFirstTrunk; | |
109 }; | |
110 #endif // __cplusplus | 79 #endif // __cplusplus |
111 | 80 |
112 #endif // CORE_INCLUDE_FXCRT_FX_MEMORY_H_ | 81 #endif // CORE_INCLUDE_FXCRT_FX_MEMORY_H_ |
OLD | NEW |