Merge pull request #2240 from GarageGames/Release_3_10_1
[Torque-3d.git] / Engine / source / util / tempAlloc.h
blob40d9a222f01cc8a4d76ec6398613b0a46bb914ca
1 //-----------------------------------------------------------------------------
2 // Copyright (c) 2012 GarageGames, LLC
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to
6 // deal in the Software without restriction, including without limitation the
7 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 // sell copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 // IN THE SOFTWARE.
21 //-----------------------------------------------------------------------------
23 #ifndef _TEMPALLOC_H_
24 #define _TEMPALLOC_H_
26 #ifndef _PLATFORM_H_
27 # include "platform/platform.h"
28 #endif
31 template< typename T >
32 struct TempAlloc
34 T* ptr;
35 U32 size;
37 TempAlloc()
38 : size( 0 ), ptr( 0 ) {}
39 TempAlloc( U32 size )
40 : size( size )
42 ptr = ( T* ) dMalloc( size * sizeof( T ) );
44 ~TempAlloc()
46 if( ptr )
47 dFree( ptr );
49 operator T*()
51 return ptr;
54 private:
55 // Not safe.
56 TempAlloc( const TempAlloc& ) {}
59 #endif // _TEMPALLOC_H_