IceMemoryMacros.h
Go to the documentation of this file.
00001 
00002 
00008 
00009 
00011 // Include Guard
00012 #ifndef __ICEMEMORYMACROS_H__
00013 #define __ICEMEMORYMACROS_H__
00014 
00015 #undef ZeroMemory
00016 #undef CopyMemory
00017 #undef MoveMemory
00018 #undef FillMemory
00019 
00027         inline_ void ZeroMemory(void* addr, udword size)                                        { memset(addr, 0, size);                }
00028 
00037         inline_ void FillMemory(void* dest, udword size, ubyte val)                     { memset(dest, val, size);              }
00038 
00048         inline_ void StoreDwords(udword* dest, udword nb, udword value)
00049         {
00050                 // The asm code below **SHOULD** be equivalent to one of those C versions
00051                 // or the other if your compiled is good: (checked on VC++ 6.0)
00052                 //
00053                 //      1) while(nb--)  *dest++ = value;
00054                 //
00055                 //      2) for(udword i=0;i<nb;i++)     dest[i] = value;
00056                 //
00057 #if defined(_MSC_VER) && not defined(_WIN64)
00058                 _asm push eax
00059                 _asm push ecx
00060                 _asm push edi
00061                 _asm mov edi, dest
00062                 _asm mov ecx, nb
00063                 _asm mov eax, value
00064                 _asm rep stosd
00065                 _asm pop edi
00066                 _asm pop ecx
00067                 _asm pop eax
00068 #else
00069                 while(nb--) *dest++ = value;
00070 #endif
00071         }
00072 
00081         inline_ void CopyMemory(void* dest, const void* src, udword size)       { memcpy(dest, src, size);              }
00082 
00091         inline_ void MoveMemory(void* dest, const void* src, udword size)       { memmove(dest, src, size);             }
00092 
00093         #define SIZEOFOBJECT            sizeof(*this)                                                                   //!< Gives the size of current object. Avoid some mistakes (e.g. "sizeof(this)").
00094         //#define CLEAROBJECT           { memset(this, 0, SIZEOFOBJECT);        }                       //!< Clears current object. Laziness is my business. HANDLE WITH CARE.
00095         #define DELETESINGLE(x)         if (x) { delete x;                              x = null; }             //!< Deletes an instance of a class.
00096         #define DELETEARRAY(x)          if (x) { delete []x;                    x = null; }             //!< Deletes an array.
00097         #define SAFE_RELEASE(x)         if (x) { (x)->Release();                (x) = null; }   //!< Safe D3D-style release
00098         #define SAFE_DESTRUCT(x)        if (x) { (x)->SelfDestruct();   (x) = null; }   //!< Safe ICE-style release
00099 
00100 #ifdef __ICEERROR_H__
00101         #define CHECKALLOC(x)           if(!x) return SetIceError("Out of memory.", EC_OUT_OF_MEMORY);  //!< Standard alloc checking. HANDLE WITH CARE.
00102 #else
00103         #define CHECKALLOC(x)           if(!x) return false;
00104 #endif
00105 
00107         #define SAFE_ALLOC(ptr, type, count)    DELETEARRAY(ptr);       ptr = new type[count];  CHECKALLOC(ptr);
00108 
00109 #endif // __ICEMEMORYMACROS_H__


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:16