summaryrefslogtreecommitdiff
path: root/xfa/src/fgas/src/crt/fx_memory.h
blob: 9ce8d2f11c2f86e3510f5b92063ab4a61d44f3ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef _FX_MEMORY_IMP
#define _FX_MEMORY_IMP
class CFX_DefStore;
class CFX_StaticStore;
class CFX_FixedStore;
class CFX_DynamicStore;
class CFX_DefStore : public IFX_MEMAllocator, public CFX_Target
{
public:
    CFX_DefStore() {}
    ~CFX_DefStore() {}
    virtual void			Release()
    {
        FXTARGET_Delete this;
    }
    virtual void*			Alloc(size_t size)
    {
        return FX_Alloc(uint8_t, size);
    }
    virtual void			Free(void *pBlock)
    {
        FX_Free(pBlock);
    }
    virtual size_t			GetBlockSize() const
    {
        return 0;
    }
    virtual size_t			GetDefChunkSize() const
    {
        return 0;
    }
    virtual size_t			SetDefChunkSize(size_t size)
    {
        return 0;
    }
    virtual size_t			GetCurrentDataSize() const
    {
        return 0;
    }
};
#if _FX_OS_ != _FX_ANDROID_
#pragma pack(push, 1)
#endif
typedef struct _FX_STATICSTORECHUNK {
    _FX_STATICSTORECHUNK*	pNextChunk;
    size_t					iChunkSize;
    size_t					iFreeSize;
} FX_STATICSTORECHUNK, * FX_LPSTATICSTORECHUNK;
typedef FX_STATICSTORECHUNK const * FX_LPCSTATICSTORECHUNK;
#if _FX_OS_ != _FX_ANDROID_
#pragma pack(pop)
#endif
class CFX_StaticStore : public IFX_MEMAllocator, public CFX_Target
{
public:
    CFX_StaticStore(size_t iDefChunkSize = 4096);
    ~CFX_StaticStore();
    virtual void			Release()
    {
        FXTARGET_Delete this;
    }
    virtual void*			Alloc(size_t size);
    virtual void			Free(void* pBlock) {}
    virtual size_t			GetBlockSize() const
    {
        return 0;
    }
    virtual size_t			GetDefChunkSize() const
    {
        return m_iDefChunkSize;
    }
    virtual size_t			SetDefChunkSize(size_t size);
    virtual size_t			GetCurrentDataSize() const
    {
        return m_iAllocatedSize;
    }
protected:
    size_t					m_iAllocatedSize;
    size_t					m_iDefChunkSize;
    FX_LPSTATICSTORECHUNK	m_pChunk;
    FX_LPSTATICSTORECHUNK	m_pLastChunk;
    FX_LPSTATICSTORECHUNK	AllocChunk(size_t size);
    FX_LPSTATICSTORECHUNK	FindChunk(size_t size);
};
#if _FX_OS_ != _FX_ANDROID_
#pragma pack(push, 1)
#endif
typedef struct _FX_FIXEDSTORECHUNK {
    uint8_t*				FirstFlag() const
    {
        return (uint8_t*)this + sizeof(_FX_FIXEDSTORECHUNK);
    }
    uint8_t*				FirstBlock() const
    {
        return FirstFlag() + iChunkSize;
    }
    _FX_FIXEDSTORECHUNK*	pNextChunk;
    size_t					iChunkSize;
    size_t					iFreeNum;
} FX_FIXEDSTORECHUNK, * FX_LPFIXEDSTORECHUNK;
typedef FX_FIXEDSTORECHUNK const * FX_LPCFIXEDSTORECHUNK;
#if _FX_OS_ != _FX_ANDROID_
#pragma pack(pop)
#endif
class CFX_FixedStore : public IFX_MEMAllocator, public CFX_Target
{
public:
    CFX_FixedStore(size_t iBlockSize, size_t iBlockNumsInChunk);
    virtual ~CFX_FixedStore();
    virtual void			Release()
    {
        FXTARGET_Delete this;
    }
    virtual void*			Alloc(size_t size);
    virtual void			Free(void* pBlock);
    virtual size_t			GetBlockSize() const
    {
        return m_iBlockSize;
    }
    virtual size_t			GetDefChunkSize() const
    {
        return m_iDefChunkSize;
    }
    virtual size_t			SetDefChunkSize(size_t iChunkSize);
    virtual size_t			GetCurrentDataSize() const
    {
        return 0;
    }
protected:
    size_t					m_iBlockSize;
    size_t					m_iDefChunkSize;
    FX_LPFIXEDSTORECHUNK	m_pChunk;
    FX_LPFIXEDSTORECHUNK	AllocChunk();
};
#if _FX_OS_ != _FX_ANDROID_
#pragma pack(push, 1)
#endif
typedef struct _FX_DYNAMICSTOREBLOCK {
    _FX_DYNAMICSTOREBLOCK*	NextBlock() const
    {
        return (_FX_DYNAMICSTOREBLOCK*)(Data() + iBlockSize);
    }
    uint8_t*				Data() const
    {
        return (uint8_t*)this + sizeof(_FX_DYNAMICSTOREBLOCK);
    }
    size_t		iBlockSize;
    FX_BOOL		bUsed;
} FX_DYNAMICSTOREBLOCK, * FX_LPDYNAMICSTOREBLOCK;
typedef FX_DYNAMICSTOREBLOCK const * FX_LPCDYNAMICSTOREBLOCK;
typedef struct _FX_DYNAMICSTORECHUNK {
    FX_LPDYNAMICSTOREBLOCK	FirstBlock() const
    {
        return (FX_LPDYNAMICSTOREBLOCK)((uint8_t*)this + sizeof(_FX_DYNAMICSTORECHUNK));
    }
    _FX_DYNAMICSTORECHUNK*	pNextChunk;
    size_t					iChunkSize;
    size_t					iFreeSize;
} FX_DYNAMICSTORECHUNK, * FX_LPDYNAMICSTORECHUNK;
typedef FX_DYNAMICSTORECHUNK const * FX_LPCDYNAMICSTORECHUNK;
#if _FX_OS_ != _FX_ANDROID_
#pragma pack(pop)
#endif
class CFX_DynamicStore : public IFX_MEMAllocator, public CFX_Target
{
public:
    CFX_DynamicStore(size_t iDefChunkSize = 4096);
    virtual ~CFX_DynamicStore();
    virtual void		Release()
    {
        FXTARGET_Delete this;
    }
    virtual void*		Alloc(size_t size);
    virtual void		Free(void* pBlock);
    virtual size_t		GetBlockSize() const
    {
        return 0;
    }
    virtual size_t		GetDefChunkSize() const
    {
        return m_iDefChunkSize;
    }
    virtual size_t		SetDefChunkSize(size_t size);
    virtual size_t		GetCurrentDataSize() const
    {
        return 0;
    }
protected:
    size_t						m_iDefChunkSize;
    FX_LPDYNAMICSTORECHUNK		m_pChunk;
    FX_LPDYNAMICSTORECHUNK		AllocChunk(size_t size);
};
#endif