X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fshared%2Fmempool.pas;h=37527dde9ee617f56d647370f4515b93e4fc72fb;hb=6cfc4749e77a32dc356f8dc4b4f26788626bbb4e;hp=73c48c1776192ed985c023bdc5196ff86783df89;hpb=31d174a428ef1235e1708b0738804b47e006cf5c;p=d2df-sdl.git diff --git a/src/shared/mempool.pas b/src/shared/mempool.pas index 73c48c1..37527dd 100644 --- a/src/shared/mempool.pas +++ b/src/shared/mempool.pas @@ -19,6 +19,7 @@ unit mempool; interface +{$IFDEF USE_MEMPOOL} uses SysUtils; @@ -56,28 +57,37 @@ type public procedure FreeInstance (); override; {$ENDIF} end; - +{$ENDIF} implementation +{$IFDEF USE_MEMPOOL} uses hashtable; type - THashPtrPtr = specialize THashBase; // key: TClass; value: PMemPool + THashKeyPtr = class + public + class function hash (const k: Pointer): LongWord; inline; + class function equ (const a, b: Pointer): Boolean; inline; + class procedure freekey (k: Pointer); inline; + end; + + THashPtrPtr = specialize THashBase; // key: TClass; value: PMemPool var pools: THashPtrPtr = nil; // ////////////////////////////////////////////////////////////////////////// // -function hashequ (constref a, b: Pointer): Boolean; begin result := (a = b); end; -function hashhash (constref a: Pointer): LongWord; begin result := fnvHash(PByte(@a)^, sizeof(a)); end; +class function THashKeyPtr.hash (const k: Pointer): LongWord; inline; begin result := fnvHash(PByte(@k)^, sizeof(k)); end; +class function THashKeyPtr.equ (const a, b: Pointer): Boolean; inline; begin result := (a = b); end; +class procedure THashKeyPtr.freekey (k: Pointer); inline; begin end; function getPoolFor (c: TClass): PMemPool; begin - if (pools = nil) then pools := THashPtrPtr.Create(hashhash, hashequ); + if (pools = nil) then pools := THashPtrPtr.Create(); if not pools.get(Pointer(c), result) then begin GetMem(result, sizeof(TMemPool)); @@ -181,4 +191,5 @@ finalization {$IF DEFINED(D2F_DEBUG) and NOT DEFINED(MEM_DISABLE_ACCOUNTING)} dumpPools(); {$ENDIF} +{$ENDIF} // USE_MEMPOOL end.