Show bonus/malus timer text if available
[ryzomcore.git] / nel / src / 3d / ps_allocator.cpp
blobeb01e4754a56ea6232ddc27f729aa69d0adea192
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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.
8 //
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/>.
17 #include "std3d.h"
18 #include "nel/3d/particle_system_process.h"
19 #include "nel/3d/ps_allocator.h"
21 #ifdef DEBUG_NEW
22 #define new DEBUG_NEW
23 #endif
25 namespace NL3D
27 #ifdef PS_FAST_ALLOC
28 uint NumPSAlloc = 0;
29 uint NumDealloc = 0;
30 NLMISC::CContiguousBlockAllocator *PSBlockAllocator= NULL;
31 static std::allocator<uint8> PSStdAllocator;
33 typedef NLMISC::CContiguousBlockAllocator *TBlocAllocPtr;
35 struct CPSAllocInfo
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)
44 CPSAllocInfo *result;
45 // if a block allocator is available, use it
46 if (PSBlockAllocator)
48 result = (CPSAllocInfo *) PSBlockAllocator->alloc(numBytes + sizeof(CPSAllocInfo));
49 result->BlocAllocator = PSBlockAllocator; // mark as a block from block allocator
51 else
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));
70 else
72 // block comes from the stl allocator
73 PSStdAllocator.deallocate((uint8 *) realAddress, ai->NumAllocatedBytes + sizeof(CPSAllocInfo));
76 #endif