1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "nel/3d/particle_system_process.h"
19 #include "nel/3d/ps_allocator.h"
30 NLMISC::CContiguousBlockAllocator
*PSBlockAllocator
= NULL
;
31 static std::allocator
<uint8
> PSStdAllocator
;
33 typedef NLMISC::CContiguousBlockAllocator
*TBlocAllocPtr
;
37 size_t NumAllocatedBytes
;
38 TBlocAllocPtr BlocAllocator
; // may be NULL if was allocated from stl allocator
41 void *PSFastMemAlloc(uint numBytes
)
43 NL_PS_FUNC(PSFastMemAlloc
)
45 // if a block allocator is available, use it
48 result
= (CPSAllocInfo
*) PSBlockAllocator
->alloc(numBytes
+ sizeof(CPSAllocInfo
));
49 result
->BlocAllocator
= PSBlockAllocator
; // mark as a block from block allocator
53 result
= (CPSAllocInfo
*) PSStdAllocator
.allocate(numBytes
+ sizeof(CPSAllocInfo
));
54 result
->BlocAllocator
= NULL
;
56 result
->NumAllocatedBytes
= numBytes
;
57 return (void *) (result
+ 1); // usable space starts after header
60 void PSFastMemFree(void *block
)
62 NL_PS_FUNC(PSFastMemFree
)
63 uint8
*realAddress
= (uint8
*) ((uint8
*) block
- sizeof(CPSAllocInfo
));
64 CPSAllocInfo
*ai
= (CPSAllocInfo
*) realAddress
;
65 if (ai
->BlocAllocator
)
67 // block comes from a block allocator
68 ai
->BlocAllocator
->free((void *) realAddress
, ai
->NumAllocatedBytes
+ sizeof(CPSAllocInfo
));
72 // block comes from the stl allocator
73 PSStdAllocator
.deallocate((uint8
*) realAddress
, ai
->NumAllocatedBytes
+ sizeof(CPSAllocInfo
));