CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
IceMemoryMacros.h
Go to the documentation of this file.
1 //----------------------------------------------------------------------
8 //----------------------------------------------------------------------
9 
10 //----------------------------------------------------------------------
11 // Include Guard
12 #ifndef RecoTracker_MkFitCore_src_Ice_IceMemoryMacros_h
13 #define RecoTracker_MkFitCore_src_Ice_IceMemoryMacros_h
14 
15 #undef ZeroMemory
16 #undef CopyMemory
17 #undef MoveMemory
18 #undef FillMemory
19 
20 #include <cstring>
21 
29 inline void ZeroMemory(void* addr, udword size) { memset(addr, 0, size); }
30 
39 inline void FillMemory(void* dest, udword size, ubyte val) { memset(dest, val, size); }
40 
41 #ifdef WIN32
42 inline_ void StoreDwords(udword* dest, udword nb, udword value) {
52  // The asm code below **SHOULD** be equivalent to one of those C versions
53  // or the other if your compiled is good: (checked on VC++ 6.0)
54  //
55  // 1) while(nb--) *dest++ = value;
56  //
57  // 2) for(udword i=0;i<nb;i++) dest[i] = value;
58  //
59  _asm push eax _asm push ecx _asm push edi _asm mov edi, dest _asm mov ecx, nb _asm mov eax,
60  value _asm rep stosd _asm pop edi _asm pop ecx _asm pop eax
61 }
62 #endif
63 
72 inline void CopyMemory(void* dest, const void* src, udword size) { memcpy(dest, src, size); }
73 
82 inline void MoveMemory(void* dest, const void* src, udword size) { memmove(dest, src, size); }
83 
84 #define SIZEOFOBJECT sizeof(*this)
85 //#define CLEAROBJECT { memset(this, 0, SIZEOFOBJECT); }
86 #define DELETESINGLE(x) \
87  if (x) { \
88  delete x; \
89  x = 0; \
90  }
91 #define DELETEARRAY(x) \
92  if (x) { \
93  operator delete[](x); \
94  x = 0; \
95  }
96 #define SAFE_RELEASE(x) \
97  if (x) { \
98  (x)->release(); \
99  (x) = 0; \
100  }
101 #define SAFE_DESTRUCT(x) \
102  if (x) { \
103  (x)->SelfDestruct(); \
104  (x) = 0; \
105  }
106 
107 #ifdef __ICEERROR_H__
108 #define CHECKALLOC(x) \
109  if (!x) \
110  return SetIceError("Out of memory.", EC_OUT_OF_MEMORY);
111 #else
112 #define CHECKALLOC(x) \
113  if (!x) \
114  return false;
115 #endif
116 
118 #define SAFE_ALLOC(ptr, type, count) \
119  DELETEARRAY(ptr); \
120  ptr = new type[count]; \
121  CHECKALLOC(ptr);
122 
123 #endif // __ICEMEMORYMACROS_H__
string rep
Definition: cuy.py:1189
#define inline_
Definition: IceTypes.h:18
void CopyMemory(void *dest, const void *src, udword size)
void FillMemory(void *dest, udword size, ubyte val)
void ZeroMemory(void *addr, udword size)
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:52
unsigned char ubyte
sizeof(ubyte) must be 1
Definition: IceTypes.h:48
void MoveMemory(void *dest, const void *src, udword size)
tuple size
Write out results.