orx  stable
Portable Game Engine
orxMemory.h
Go to the documentation of this file.
1 /* Orx - Portable Game Engine
2  *
3  * Copyright (c) 2008-2017 Orx-Project
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  *
18  * 2. Altered source versions must be plainly marked as such, and must not be
19  * misrepresented as being the original software.
20  *
21  * 3. This notice may not be removed or altered from any source
22  * distribution.
23  */
24 
45 #ifndef _orxMEMORY_H_
46 #define _orxMEMORY_H_
47 
48 
49 #include "orxInclude.h"
50 #include "debug/orxDebug.h"
51 
52 #include <string.h>
53 
54 
55 #ifdef __orxWINDOWS__
56  #ifdef NO_WIN32_LEAN_AND_MEAN
57  #undef WIN32_LEAN_AND_MEAN
58  #else /* NO_WIN32_LEAN_AND_MEAN */
59  #ifndef WIN32_LEAN_AND_MEAN
60  #define WIN32_LEAN_AND_MEAN
61  #define DEFINED_WIN32_LEAN_AND_MEAN
62  #endif /* !WIN32_LEAN_AND_MEAN */
63  #endif /* NO_WIN32_LEAN_AND_MEAN */
64  #include <windows.h>
65  #ifdef DEFINED_WIN32_LEAN_AND_MEAN
66  #undef WIN32_LEAN_AND_MEAN
67  #undef DEFINED_WIN32_LEAN_AND_MEAN
68  #endif /* DEFINED_WIN32_LEAN_AND_MEAN */
69  #undef NO_WIN32_LEAN_AND_MEAN
70 #endif /* __orxWINDOWS__ */
71 
72 
74 #if defined(__orxGCC__) || defined(__orxLLVM__)
75  #define orxMEMORY_BARRIER() __sync_synchronize()
76  #define orxHAS_MEMORY_BARRIER
77 #elif defined(__orxMSVC__)
78  #define orxMEMORY_BARRIER() MemoryBarrier()
79  #define orxHAS_MEMORY_BARRIER
80 #else
81  #define orxMEMORY_BARRIER()
82  #undef orxHAS_MEMORY_BARRIER
83 
84  #warning !!WARNING!! This compiler does not have any hardware memory barrier builtin.
85 #endif
86 
87 
89 #ifdef __orxPROFILER__
90  #define orxMEMORY_TRACK(TYPE, SIZE, ALLOCATE) orxMemory_Track(orxMEMORY_TYPE_##TYPE, SIZE, ALLOCATE)
91 #else /* __orxPROFILER__ */
92  #define orxMEMORY_TRACK(TYPE, SIZE, ALLOCATE)
93 #endif /* __orxPROFILER__ */
94 
95 
98 typedef enum __orxMEMORY_TYPE_t
99 {
112  orxMEMORY_TYPE_NONE = orxENUM_NONE
115 
116 
119 extern orxDLLAPI void orxFASTCALL orxMemory_Setup();
120 
124 extern orxDLLAPI orxSTATUS orxFASTCALL orxMemory_Init();
125 
128 extern orxDLLAPI void orxFASTCALL orxMemory_Exit();
129 
135 extern orxDLLAPI void *orxFASTCALL orxMemory_Allocate(orxU32 _u32Size, orxMEMORY_TYPE _eMemType);
136 
144 extern orxDLLAPI void *orxFASTCALL orxMemory_Reallocate(void *_pMem, orxU32 _u32Size);
145 
149 extern orxDLLAPI void orxFASTCALL orxMemory_Free(void *_pMem);
150 
151 
159 static orxINLINE void * orxMemory_Copy(void *_pDest, const void *_pSrc, orxU32 _u32Size)
160 {
161  /* Checks */
162  orxASSERT(_pDest != orxNULL);
163  orxASSERT(_pSrc != orxNULL);
164 
165  /* Done! */
166  return((void *)memcpy(_pDest, _pSrc, (size_t)_u32Size));
167 }
168 
175 static orxINLINE void * orxMemory_Move(void *_pDest, void *_pSrc, orxU32 _u32Size)
176 {
177  /* Checks */
178  orxASSERT(_pDest != orxNULL);
179  orxASSERT(_pSrc != orxNULL);
180 
181  /* Done! */
182  return((void *)memmove(_pDest, _pSrc, (size_t)_u32Size));
183 }
184 
191 static orxINLINE orxU32 orxMemory_Compare(const void *_pMem1, const void *_pMem2, orxU32 _u32Size)
192 {
193  /* Checks */
194  orxASSERT(_pMem1 != orxNULL);
195  orxASSERT(_pMem2 != orxNULL);
196 
197  /* Done! */
198  return((orxU32)memcmp(_pMem1, _pMem2, (size_t)_u32Size));
199 }
200 
207 static orxINLINE void * orxMemory_Set(void *_pDest, orxU8 _u8Data, orxU32 _u32Size)
208 {
209  /* Checks */
210  orxASSERT(_pDest != orxNULL);
211 
212  /* Done! */
213  return((void *)memset(_pDest, _u8Data, (size_t)_u32Size));
214 }
215 
221 static orxINLINE void * orxMemory_Zero(void *_pDest, orxU32 _u32Size)
222 {
223  /* Checks */
224  orxASSERT(_pDest != orxNULL);
225 
226  /* Done! */
227  return((void *)memset(_pDest, 0, (size_t)_u32Size));
228 }
229 
230 
235 extern orxDLLAPI const orxSTRING orxFASTCALL orxMemory_GetTypeName(orxMEMORY_TYPE _eMemType);
236 
237 
241 extern orxDLLAPI orxU32 orxFASTCALL orxMemory_GetCacheLineSize();
242 
243 
244 #ifdef __orxPROFILER__
245 
255 extern orxDLLAPI orxSTATUS orxFASTCALL orxMemory_GetUsage(orxMEMORY_TYPE _eMemType, orxU32 *_pu32Counter, orxU32 *_pu32PeakCounter, orxU32 *_pu32Size, orxU32 *_pu32PeakSize, orxU32 *_pu32OperationCounter);
256 
257 
264 extern orxDLLAPI orxSTATUS orxFASTCALL orxMemory_Track(orxMEMORY_TYPE _eMemType, orxU32 _u32Size, orxBOOL _bAllocate);
265 
266 #endif /* __orxPROFILER__ */
267 
268 #endif /* _orxMEMORY_H_ */
269 
orxDLLAPI void *orxFASTCALL orxMemory_Allocate(orxU32 _u32Size, orxMEMORY_TYPE _eMemType)
orxMEMORY_TYPE
Definition: orxMemory.h:98
static orxINLINE void * orxMemory_Move(void *_pDest, void *_pSrc, orxU32 _u32Size)
Definition: orxMemory.h:175
orxDLLAPI void orxFASTCALL orxMemory_Setup()
orxSTATUS
Definition: orxType.h:243
orxDLLAPI void *orxFASTCALL orxMemory_Reallocate(void *_pMem, orxU32 _u32Size)
orxDLLAPI orxSTATUS orxFASTCALL orxMemory_Init()
static orxINLINE void * orxMemory_Zero(void *_pDest, orxU32 _u32Size)
Definition: orxMemory.h:221
static orxINLINE void * orxMemory_Set(void *_pDest, orxU8 _u8Data, orxU32 _u32Size)
Definition: orxMemory.h:207
#define orxDLLAPI
Definition: orxDecl.h:387
orxDLLAPI const orxSTRING orxFASTCALL orxMemory_GetTypeName(orxMEMORY_TYPE _eMemType)
orxDLLAPI void orxFASTCALL orxMemory_Free(void *_pMem)
static orxINLINE void * orxMemory_Copy(void *_pDest, const void *_pSrc, orxU32 _u32Size)
Definition: orxMemory.h:159
static orxINLINE orxU32 orxMemory_Compare(const void *_pMem1, const void *_pMem2, orxU32 _u32Size)
Definition: orxMemory.h:191
orxDLLAPI void orxFASTCALL orxMemory_Exit()
#define orxASSERT(TEST,...)
Definition: orxDebug.h:298
orxDLLAPI orxU32 orxFASTCALL orxMemory_GetCacheLineSize()

Generated for orx by doxygen 1.5.6