orx  1.14
Portable Game Engine
orxMemory.h
Go to the documentation of this file.
1 /* Orx - Portable Game Engine
2  *
3  * Copyright (c) 2008-2022 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 
134 extern orxDLLAPI void *orxFASTCALL orxMemory_Reallocate(void *_pMem, orxU32 _u32Size, orxMEMORY_TYPE _eMemType);
135 
139 extern orxDLLAPI void orxFASTCALL orxMemory_Free(void *_pMem);
140 
141 
149 static orxINLINE void * orxMemory_Copy(void *_pDest, const void *_pSrc, orxU32 _u32Size)
150 {
151  /* Checks */
152  orxASSERT(_pDest != orxNULL);
153  orxASSERT(_pSrc != orxNULL);
154 
155  /* Done! */
156  return((void *)memcpy(_pDest, _pSrc, (size_t)_u32Size));
157 }
158 
165 static orxINLINE void * orxMemory_Move(void *_pDest, const void *_pSrc, orxU32 _u32Size)
166 {
167  /* Checks */
168  orxASSERT(_pDest != orxNULL);
169  orxASSERT(_pSrc != orxNULL);
170 
171  /* Done! */
172  return((void *)memmove(_pDest, _pSrc, (size_t)_u32Size));
173 }
174 
181 static orxINLINE orxU32 orxMemory_Compare(const void *_pMem1, const void *_pMem2, orxU32 _u32Size)
182 {
183  /* Checks */
184  orxASSERT(_pMem1 != orxNULL);
185  orxASSERT(_pMem2 != orxNULL);
186 
187  /* Done! */
188  return((orxU32)memcmp(_pMem1, _pMem2, (size_t)_u32Size));
189 }
190 
197 static orxINLINE void * orxMemory_Set(void *_pDest, orxU8 _u8Data, orxU32 _u32Size)
198 {
199  /* Checks */
200  orxASSERT(_pDest != orxNULL);
201 
202  /* Done! */
203  return((void *)memset(_pDest, _u8Data, (size_t)_u32Size));
204 }
205 
211 static orxINLINE void * orxMemory_Zero(void *_pDest, orxU32 _u32Size)
212 {
213  /* Checks */
214  orxASSERT(_pDest != orxNULL);
215 
216  /* Done! */
217  return((void *)memset(_pDest, 0, (size_t)_u32Size));
218 }
219 
220 
225 extern orxDLLAPI const orxSTRING orxFASTCALL orxMemory_GetTypeName(orxMEMORY_TYPE _eMemType);
226 
227 
231 extern orxDLLAPI orxU32 orxFASTCALL orxMemory_GetCacheLineSize();
232 
233 
234 #ifdef __orxPROFILER__
235 
245 extern orxDLLAPI orxSTATUS orxFASTCALL orxMemory_GetUsage(orxMEMORY_TYPE _eMemType, orxU64 *_pu64Count, orxU64 *_pu64PeakCount, orxU64 *_pu64Size, orxU64 *_pu64PeakSize, orxU64 *_pu64OperationCount);
246 
247 
254 extern orxDLLAPI orxSTATUS orxFASTCALL orxMemory_Track(orxMEMORY_TYPE _eMemType, orxU32 _u32Size, orxBOOL _bAllocate);
255 
256 #endif /* __orxPROFILER__ */
257 
258 #endif /* _orxMEMORY_H_ */
259 
orxDLLAPI void *orxFASTCALL orxMemory_Allocate(orxU32 _u32Size, orxMEMORY_TYPE _eMemType)
orxMEMORY_TYPE
Definition: orxMemory.h:87
orxDLLAPI void orxFASTCALL orxMemory_Setup()
orxSTATUS
Definition: orxType.h:256
orxDLLAPI orxSTATUS orxFASTCALL orxMemory_Init()
static orxINLINE void * orxMemory_Zero(void *_pDest, orxU32 _u32Size)
Definition: orxMemory.h:211
static orxINLINE void * orxMemory_Set(void *_pDest, orxU8 _u8Data, orxU32 _u32Size)
Definition: orxMemory.h:197
#define orxDLLAPI
Definition: orxDecl.h:370
orxDLLAPI const orxSTRING orxFASTCALL orxMemory_GetTypeName(orxMEMORY_TYPE _eMemType)
orxDLLAPI void orxFASTCALL orxMemory_Free(void *_pMem)
static orxINLINE void * orxMemory_Move(void *_pDest, const void *_pSrc, orxU32 _u32Size)
Definition: orxMemory.h:165
static orxINLINE void * orxMemory_Copy(void *_pDest, const void *_pSrc, orxU32 _u32Size)
Definition: orxMemory.h:149
static orxINLINE orxU32 orxMemory_Compare(const void *_pMem1, const void *_pMem2, orxU32 _u32Size)
Definition: orxMemory.h:181
orxDLLAPI void orxFASTCALL orxMemory_Exit()
#define orxASSERT(TEST,...)
Definition: orxDebug.h:372
orxDLLAPI void *orxFASTCALL orxMemory_Reallocate(void *_pMem, orxU32 _u32Size, orxMEMORY_TYPE _eMemType)
orxDLLAPI orxU32 orxFASTCALL orxMemory_GetCacheLineSize()

Generated for orx by doxygen 1.8.11