orx  1.10
Portable Game Engine
orxMemory.h
Go to the documentation of this file.
1 /* Orx - Portable Game Engine
2  *
3  * Copyright (c) 2008-2019 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 
55 #if defined(__orxGCC__) || defined(__orxLLVM__)
56  #define orxMEMORY_BARRIER() __sync_synchronize()
57  #define orxHAS_MEMORY_BARRIER
58 #elif defined(__orxMSVC__)
59  #ifdef __orx64__
60  #define orxMEMORY_BARRIER() __faststorefence()
61 #else /* __orx64__ */
62  #define orxMEMORY_BARRIER() \
63  { \
64  long lBarrier; \
65  _InterlockedOr(&lBarrier, 0); \
66  }
67 #endif /* __orx64__ */
68  #define orxHAS_MEMORY_BARRIER
69 #else
70  #define orxMEMORY_BARRIER()
71  #undef orxHAS_MEMORY_BARRIER
72 
73  #warning !!WARNING!! This compiler does not have any builtin hardware memory barrier.
74 #endif
75 
76 
78 #ifdef __orxPROFILER__
79  #define orxMEMORY_TRACK(TYPE, SIZE, ALLOCATE) orxMemory_Track(orxMEMORY_TYPE_##TYPE, SIZE, ALLOCATE)
80 #else /* __orxPROFILER__ */
81  #define orxMEMORY_TRACK(TYPE, SIZE, ALLOCATE)
82 #endif /* __orxPROFILER__ */
83 
84 
87 typedef enum __orxMEMORY_TYPE_t
88 {
101  orxMEMORY_TYPE_NONE = orxENUM_NONE
104 
105 
108 extern orxDLLAPI void orxFASTCALL orxMemory_Setup();
109 
113 extern orxDLLAPI orxSTATUS orxFASTCALL orxMemory_Init();
114 
117 extern orxDLLAPI void orxFASTCALL orxMemory_Exit();
118 
124 extern orxDLLAPI void *orxFASTCALL orxMemory_Allocate(orxU32 _u32Size, orxMEMORY_TYPE _eMemType);
125 
133 extern orxDLLAPI void *orxFASTCALL orxMemory_Reallocate(void *_pMem, orxU32 _u32Size);
134 
138 extern orxDLLAPI void orxFASTCALL orxMemory_Free(void *_pMem);
139 
140 
148 static orxINLINE void * orxMemory_Copy(void *_pDest, const void *_pSrc, orxU32 _u32Size)
149 {
150  /* Checks */
151  orxASSERT(_pDest != orxNULL);
152  orxASSERT(_pSrc != orxNULL);
153 
154  /* Done! */
155  return((void *)memcpy(_pDest, _pSrc, (size_t)_u32Size));
156 }
157 
164 static orxINLINE void * orxMemory_Move(void *_pDest, void *_pSrc, orxU32 _u32Size)
165 {
166  /* Checks */
167  orxASSERT(_pDest != orxNULL);
168  orxASSERT(_pSrc != orxNULL);
169 
170  /* Done! */
171  return((void *)memmove(_pDest, _pSrc, (size_t)_u32Size));
172 }
173 
180 static orxINLINE orxU32 orxMemory_Compare(const void *_pMem1, const void *_pMem2, orxU32 _u32Size)
181 {
182  /* Checks */
183  orxASSERT(_pMem1 != orxNULL);
184  orxASSERT(_pMem2 != orxNULL);
185 
186  /* Done! */
187  return((orxU32)memcmp(_pMem1, _pMem2, (size_t)_u32Size));
188 }
189 
196 static orxINLINE void * orxMemory_Set(void *_pDest, orxU8 _u8Data, orxU32 _u32Size)
197 {
198  /* Checks */
199  orxASSERT(_pDest != orxNULL);
200 
201  /* Done! */
202  return((void *)memset(_pDest, _u8Data, (size_t)_u32Size));
203 }
204 
210 static orxINLINE void * orxMemory_Zero(void *_pDest, orxU32 _u32Size)
211 {
212  /* Checks */
213  orxASSERT(_pDest != orxNULL);
214 
215  /* Done! */
216  return((void *)memset(_pDest, 0, (size_t)_u32Size));
217 }
218 
219 
224 extern orxDLLAPI const orxSTRING orxFASTCALL orxMemory_GetTypeName(orxMEMORY_TYPE _eMemType);
225 
226 
230 extern orxDLLAPI orxU32 orxFASTCALL orxMemory_GetCacheLineSize();
231 
232 
233 #ifdef __orxPROFILER__
234 
244 extern orxDLLAPI orxSTATUS orxFASTCALL orxMemory_GetUsage(orxMEMORY_TYPE _eMemType, orxU32 *_pu32Count, orxU32 *_pu32PeakCount, orxU32 *_pu32Size, orxU32 *_pu32PeakSize, orxU32 *_pu32OperationCount);
245 
246 
253 extern orxDLLAPI orxSTATUS orxFASTCALL orxMemory_Track(orxMEMORY_TYPE _eMemType, orxU32 _u32Size, orxBOOL _bAllocate);
254 
255 #endif /* __orxPROFILER__ */
256 
257 #endif /* _orxMEMORY_H_ */
258 
orxDLLAPI void *orxFASTCALL orxMemory_Allocate(orxU32 _u32Size, orxMEMORY_TYPE _eMemType)
orxMEMORY_TYPE
Definition: orxMemory.h:87
static orxINLINE void * orxMemory_Move(void *_pDest, void *_pSrc, orxU32 _u32Size)
Definition: orxMemory.h:164
orxDLLAPI void orxFASTCALL orxMemory_Setup()
orxSTATUS
Definition: orxType.h:246
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:210
static orxINLINE void * orxMemory_Set(void *_pDest, orxU8 _u8Data, orxU32 _u32Size)
Definition: orxMemory.h:196
#define orxDLLAPI
Definition: orxDecl.h:381
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:148
static orxINLINE orxU32 orxMemory_Compare(const void *_pMem1, const void *_pMem2, orxU32 _u32Size)
Definition: orxMemory.h:180
orxDLLAPI void orxFASTCALL orxMemory_Exit()
#define orxASSERT(TEST,...)
Definition: orxDebug.h:353
orxDLLAPI orxU32 orxFASTCALL orxMemory_GetCacheLineSize()

Generated for orx by doxygen 1.8.11