29 #ifndef ARRAY_INCLUDED
30 #define ARRAY_INCLUDED
36 #define ASSERT( x ) { if( !( x ) ) __debugbreak(); }
39 #define ASSERT( x ) { if( !( x ) ) _asm{ int 0x03 } }
41 #define ASSERT( x ) { if( !( x ) ) exit(0); }
46 void* aligned_malloc(
size_t size ,
size_t align )
49 void* mem = malloc( size + align +
sizeof(
void* ) );
51 char* amem = ( (
char*)mem ) +
sizeof(
void* );
53 amem = (
char* )( ( (
size_t)( ( (
char*)amem ) + (align-1) ) ) & ~( align-1 ) );
55 ( (
void** ) amem )[-1] = mem;
58 void aligned_free(
void* mem ) { free( ( (
void** )mem )[-1] ); }
61 #pragma message ( "[WARNING] Array debugging is enabled" )
63 #define Pointer( ... ) Array< __VA_ARGS__ >
64 #define ConstPointer( ... ) ConstArray< __VA_ARGS__ >
65 template<
class C >
void FreePointer(
Array< C >& a ){ a.Free( ); }
66 template<
class C >
void AlignedFreePointer(
Array< C >& a ){ a.Free( ); }
67 template<
class C >
void VFreePointer(
Array< C >& a ){ a.Free( ); }
68 template<
class C >
void DeletePointer(
Array< C >& a ){ a.Delete( ); }
70 template<
class C >
Array< C > NewPointer(
size_t size ,
const char* name=NULL ){
return Array< C >::New ( size , name ); }
71 template<
class C >
Array< C > AllocPointer(
size_t size ,
const char* name=NULL ){
return Array< C >::Alloc ( size ,
false , name ); }
72 template<
class C >
Array< C > AlignedAllocPointer(
size_t size ,
size_t alignment ,
const char* name=NULL ){
return Array< C >::AlignedAlloc( size , alignment ,
false , name ); }
77 template<
class C > C* PointerAddress(
Array< C >& a ) {
return a.pointer(); }
78 template<
class C >
const C* PointerAddress(
ConstArray< C >& a ) {
return a.pointer(); }
85 #define Pointer( ... ) __VA_ARGS__*
86 #define ConstPointer( ... ) const __VA_ARGS__*
88 #define FreePointer( ... ) { if( __VA_ARGS__ ) free( __VA_ARGS__ ) , __VA_ARGS__ = NULL; }
89 #define AlignedFreePointer( ... ) { if( __VA_ARGS__ ) aligned_free( __VA_ARGS__ ) , __VA_ARGS__ = NULL; }
90 #define DeletePointer( ... ) { if( __VA_ARGS__ ) delete[] __VA_ARGS__ , __VA_ARGS__ = NULL; }
92 template<
class C > C* NewPointer(
size_t size ,
const char* name=NULL ){
return new C[size]; }
93 template<
class C > C* AllocPointer(
size_t size ,
const char* name=NULL ){
return static_cast<C*
> (malloc(
sizeof(C) * size )); }
94 template<
class C > C* AlignedAllocPointer(
size_t size ,
size_t alignment ,
const char* name=NULL ){
return static_cast<C*
>(aligned_malloc(
sizeof(C) * size , alignment )); }
95 template<
class C > C* ReAllocPointer( C* c ,
size_t size ,
const char* name=NULL ){
return static_cast<C*
> (realloc( c ,
sizeof(C) * size )); }
97 template<
class C > C* NullPointer(
void ){
return NULL; }
99 template<
class C > C* PointerAddress( C* c ){
return c; }
100 template<
class C >
const C* PointerAddress(
const C* c ){
return c; }
101 template<
class C > C* GetPointer( C& c ){
return &c; }
102 template<
class C >
const C* GetPointer(
const C& c ){
return &c; }
103 template<
class C > C* GetPointer( std::vector< C >& v ){
return &v[0]; }
104 template<
class C >
const C* GetPointer(
const std::vector< C >& v ){
return &v[0]; }
105 #endif // ARRAY_DEBUG
106 #endif // ARRAY_INCLUDED