Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IceMemoryMacros.h
Go to the documentation of this file.
1 
8 
11 // Include Guard
12 #ifndef __ICEMEMORYMACROS_H__
13 #define __ICEMEMORYMACROS_H__
14 
15 #undef ZeroMemory
16 #undef CopyMemory
17 #undef MoveMemory
18 #undef FillMemory
19 
27  inline_ void ZeroMemory(void* addr, udword size) { memset(addr, 0, size); }
28 
37  inline_ void FillMemory(void* dest, udword size, ubyte val) { memset(dest, val, size); }
38 
48  inline_ void StoreDwords(udword* dest, udword nb, udword value)
49  {
50  // The asm code below **SHOULD** be equivalent to one of those C versions
51  // or the other if your compiled is good: (checked on VC++ 6.0)
52  //
53  // 1) while(nb--) *dest++ = value;
54  //
55  // 2) for(udword i=0;i<nb;i++) dest[i] = value;
56  //
57  /*_asm push eax
58  _asm push ecx
59  _asm push edi
60  _asm mov edi, dest
61  _asm mov ecx, nb
62  _asm mov eax, value
63  _asm rep stosd
64  _asm pop edi
65  _asm pop ecx
66  _asm pop eax*/
67  while(nb--) *dest++ = value;
68  }
69 
78  inline_ void CopyMemory(void* dest, const void* src, udword size) { memcpy(dest, src, size); }
79 
88  inline_ void MoveMemory(void* dest, const void* src, udword size) { memmove(dest, src, size); }
89 
90  #define SIZEOFOBJECT sizeof(*this)
91  //#define CLEAROBJECT { memset(this, 0, SIZEOFOBJECT); }
92  #define DELETESINGLE(x) { delete x; x = null; }
93  #define DELETEARRAY(x) { delete []x; x = null; }
94  #define SAFE_RELEASE(x) if (x) { (x)->Release(); (x) = null; }
95  #define SAFE_DESTRUCT(x) if (x) { (x)->SelfDestruct(); (x) = null; }
96 
97 #ifdef __ICEERROR_H__
98  #define CHECKALLOC(x) if(!x) return SetIceError("Out of memory.", EC_OUT_OF_MEMORY);
99 #else
100  #define CHECKALLOC(x) if(!x) return false;
101 #endif
102 
104  #define SAFE_ALLOC(ptr, type, count) DELETEARRAY(ptr); ptr = new type[count]; CHECKALLOC(ptr);
105 
106 #endif // __ICEMEMORYMACROS_H__