OLD | NEW |
| (Empty) |
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 XFA_SRC_FGAS_CRT_FGAS_MEMORY_H_ | |
8 #define XFA_SRC_FGAS_CRT_FGAS_MEMORY_H_ | |
9 | |
10 #include "core/include/fxcrt/fx_memory.h" | |
11 #include "core/include/fxcrt/fx_system.h" | |
12 | |
13 class IFX_MEMAllocator; | |
14 class CFX_Target; | |
15 enum FX_ALLOCTYPE { | |
16 FX_ALLOCTYPE_Default = 0, | |
17 FX_ALLOCTYPE_Static, | |
18 FX_ALLOCTYPE_Fixed, | |
19 FX_ALLOCTYPE_Dynamic, | |
20 }; | |
21 | |
22 class IFX_MEMAllocator { | |
23 public: | |
24 virtual ~IFX_MEMAllocator() {} | |
25 virtual void Release() = 0; | |
26 virtual void* Alloc(size_t size) = 0; | |
27 virtual void Free(void* pBlock) = 0; | |
28 virtual size_t GetBlockSize() const = 0; | |
29 virtual size_t GetDefChunkSize() const = 0; | |
30 virtual size_t SetDefChunkSize(size_t size) = 0; | |
31 virtual size_t GetCurrentDataSize() const = 0; | |
32 }; | |
33 | |
34 IFX_MEMAllocator* FX_CreateAllocator(FX_ALLOCTYPE eType, | |
35 size_t chunkSize, | |
36 size_t blockSize); | |
37 class CFX_Target { | |
38 public: | |
39 virtual ~CFX_Target() {} | |
40 void* operator new(size_t size) { return FX_Alloc(uint8_t, size); } | |
41 void operator delete(void* p) { FX_Free(p); } | |
42 void* operator new(size_t size, IFX_MEMAllocator* pAllocator) { | |
43 return pAllocator->Alloc(size); | |
44 } | |
45 void operator delete(void* p, IFX_MEMAllocator* pAllocator) { | |
46 pAllocator->Free(p); | |
47 } | |
48 void* operator new(size_t size, void* place) { return place; } | |
49 void operator delete(void* p, void* place) {} | |
50 }; | |
51 | |
52 #define FXTARGET_NewWith(__allocator__) new (__allocator__) | |
53 #define FXTARGET_DeleteWith(__class__, __allocator__, pointer) \ | |
54 { \ | |
55 (pointer)->~__class__(); \ | |
56 (pointer)->operator delete((pointer), (__allocator__)); \ | |
57 } | |
58 | |
59 #endif // XFA_SRC_FGAS_CRT_FGAS_MEMORY_H_ | |
OLD | NEW |