| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2 |
/** |
| 3 |
* Contains all memory macros. |
| 4 |
* \file IceMemoryMacros.h |
| 5 |
* \author Pierre Terdiman |
| 6 |
* \date April, 4, 2000 |
| 7 |
*/ |
| 8 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 9 |
|
| 10 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 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 |
|
| 20 |
//! Clears a buffer. |
| 21 |
//! \param addr [in] buffer address |
| 22 |
//! \param size [in] buffer length |
| 23 |
//! \see FillMemory |
| 24 |
//! \see StoreDwords |
| 25 |
//! \see CopyMemory |
| 26 |
//! \see MoveMemory |
| 27 |
inline_ void ZeroMemory(void* addr, udword size) { memset(addr, 0, size); } |
| 28 |
|
| 29 |
//! Fills a buffer with a given byte. |
| 30 |
//! \param addr [in] buffer address |
| 31 |
//! \param size [in] buffer length |
| 32 |
//! \param val [in] the byte value |
| 33 |
//! \see StoreDwords |
| 34 |
//! \see ZeroMemory |
| 35 |
//! \see CopyMemory |
| 36 |
//! \see MoveMemory |
| 37 |
inline_ void FillMemory(void* dest, udword size, ubyte val) { memset(dest, val, size); } |
| 38 |
|
| 39 |
//! Fills a buffer with a given dword. |
| 40 |
//! \param addr [in] buffer address |
| 41 |
//! \param nb [in] number of dwords to write |
| 42 |
//! \param value [in] the dword value |
| 43 |
//! \see FillMemory |
| 44 |
//! \see ZeroMemory |
| 45 |
//! \see CopyMemory |
| 46 |
//! \see MoveMemory |
| 47 |
//! \warning writes nb*4 bytes ! |
| 48 |
inline_ void StoreDwords(udword* dest, udword nb, udword value) |
| 49 |
{ |
| 50 |
while(nb--) *dest++ = value; |
| 51 |
} |
| 52 |
|
| 53 |
//! Copies a buffer. |
| 54 |
//! \param addr [in] destination buffer address |
| 55 |
//! \param addr [in] source buffer address |
| 56 |
//! \param size [in] buffer length |
| 57 |
//! \see ZeroMemory |
| 58 |
//! \see FillMemory |
| 59 |
//! \see StoreDwords |
| 60 |
//! \see MoveMemory |
| 61 |
inline_ void CopyMemory(void* dest, const void* src, udword size) { memcpy(dest, src, size); } |
| 62 |
|
| 63 |
//! Moves a buffer. |
| 64 |
//! \param addr [in] destination buffer address |
| 65 |
//! \param addr [in] source buffer address |
| 66 |
//! \param size [in] buffer length |
| 67 |
//! \see ZeroMemory |
| 68 |
//! \see FillMemory |
| 69 |
//! \see StoreDwords |
| 70 |
//! \see CopyMemory |
| 71 |
inline_ void MoveMemory(void* dest, const void* src, udword size) { memmove(dest, src, size); } |
| 72 |
|
| 73 |
#define SIZEOFOBJECT sizeof(*this) //!< Gives the size of current object. Avoid some mistakes (e.g. "sizeof(this)"). |
| 74 |
//#define CLEAROBJECT { memset(this, 0, SIZEOFOBJECT); } //!< Clears current object. Laziness is my business. HANDLE WITH CARE. |
| 75 |
#define DELETESINGLE(x) if (x) { delete x; x = null; } //!< Deletes an instance of a class. |
| 76 |
#define DELETEARRAY(x) if (x) { delete []x; x = null; } //!< Deletes an array. |
| 77 |
#define SAFE_RELEASE(x) if (x) { (x)->Release(); (x) = null; } //!< Safe D3D-style release |
| 78 |
#define SAFE_DESTRUCT(x) if (x) { (x)->SelfDestruct(); (x) = null; } //!< Safe ICE-style release |
| 79 |
|
| 80 |
#ifdef __ICEERROR_H__ |
| 81 |
#define CHECKALLOC(x) if(!x) return SetIceError("Out of memory.", EC_OUT_OF_MEMORY); //!< Standard alloc checking. HANDLE WITH CARE. |
| 82 |
#else |
| 83 |
#define CHECKALLOC(x) if(!x) return false; |
| 84 |
#endif |
| 85 |
|
| 86 |
#endif // __ICEMEMORYMACROS_H__ |