1 (* Copyright (C) DooM 2D:Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE a_modes.inc}
17 {$DEFINE MEM_DISABLE_ACCOUNTING}
20 interface
22 {$IFDEF USE_MEMPOOL}
23 uses
24 SysUtils;
27 type
30 private
38 public
47 public
55 {$IF DEFINED(D2F_DEBUG) and NOT DEFINED(MEM_DISABLE_ACCOUNTING)}
58 {$ENDIF}
60 {$ENDIF}
62 implementation
64 {$IFDEF USE_MEMPOOL}
65 uses
66 hashtable;
68 type
70 public
76 THashPtrPtr = specialize THashBase<Pointer, PMemPool, THashKeyPtr>; // key: TClass; value: PMemPool
78 var
82 // ////////////////////////////////////////////////////////////////////////// //
83 class function THashKeyPtr.hash (const k: Pointer): LongWord; inline; begin result := fnvHash(PByte(@k)^, sizeof(k)); end;
84 class function THashKeyPtr.equ (const a, b: Pointer): Boolean; inline; begin result := (a = b); end;
89 begin
92 begin
100 // ////////////////////////////////////////////////////////////////////////// //
102 begin
113 procedure TMemPool.setCapacity (acount: Integer); // ensure capacity for at least `acount` objects
114 begin
119 begin
124 begin
134 begin
139 // ////////////////////////////////////////////////////////////////////////// //
140 {$IF DEFINED(D2F_DEBUG) and NOT DEFINED(MEM_DISABLE_ACCOUNTING)}
142 var
143 {$IF DEFINED(D2F_DEBUG) and NOT DEFINED(MEM_DISABLE_ACCOUNTING)}
145 {$ENDIF}
147 begin
148 {$IF DEFINED(D2F_DEBUG) and NOT DEFINED(MEM_DISABLE_ACCOUNTING)}
151 {$ELSE}
154 {$ENDIF}
161 var
163 begin
167 {$ENDIF}
170 // ////////////////////////////////////////////////////////////////////////// //
171 {$IF DEFINED(D2F_DEBUG) and NOT DEFINED(MEM_DISABLE_ACCOUNTING)}
173 var
176 begin
180 begin
185 {$ENDIF}
188 initialization
189 //mpoolMap := TMemPool.Create('textmap', 64);
190 finalization
191 {$IF DEFINED(D2F_DEBUG) and NOT DEFINED(MEM_DISABLE_ACCOUNTING)}
193 {$ENDIF}