orx 1.16
Portable Game Engine
Loading...
Searching...
No Matches
orxMemory.h
Go to the documentation of this file.
1/* Orx - Portable Game Engine
2 *
3 * Copyright (c) 2008- 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
34
43
44
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
86#if !defined(__orxWINDOWS__)
87 #include <alloca.h>
88#endif /* !__orxWINDOWS__ */
89#define orxMemory_StackAllocate(x) alloca((x))
90
91
111
112
115extern orxDLLAPI void orxFASTCALL orxMemory_Setup();
116
120extern orxDLLAPI orxSTATUS orxFASTCALL orxMemory_Init();
121
124extern orxDLLAPI void orxFASTCALL orxMemory_Exit();
125
130
133extern orxDLLAPI void orxFASTCALL orxMemory_ExitThread();
134
140extern orxDLLAPI void *orxFASTCALL orxMemory_Allocate(orxU32 _u32Size, orxMEMORY_TYPE _eMemType);
141
150extern orxDLLAPI void *orxFASTCALL orxMemory_Reallocate(void *_pMem, orxU32 _u32Size, orxMEMORY_TYPE _eMemType);
151
155extern orxDLLAPI void orxFASTCALL orxMemory_Free(void *_pMem);
156
157
165static orxINLINE void * orxMemory_Copy(void *_pDest, const void *_pSrc, orxU32 _u32Size)
166{
167 /* Checks */
168 orxASSERT(_pDest != orxNULL);
169 orxASSERT(_pSrc != orxNULL);
170
171 /* Done! */
172 return((void *)memcpy(_pDest, _pSrc, (size_t)_u32Size));
173}
174
181static orxINLINE void * orxMemory_Move(void *_pDest, const void *_pSrc, orxU32 _u32Size)
182{
183 /* Checks */
184 orxASSERT(_pDest != orxNULL);
185 orxASSERT(_pSrc != orxNULL);
186
187 /* Done! */
188 return((void *)memmove(_pDest, _pSrc, (size_t)_u32Size));
189}
190
197static orxINLINE orxU32 orxMemory_Compare(const void *_pMem1, const void *_pMem2, orxU32 _u32Size)
198{
199 /* Checks */
200 orxASSERT(_pMem1 != orxNULL);
201 orxASSERT(_pMem2 != orxNULL);
202
203 /* Done! */
204 return((orxU32)memcmp(_pMem1, _pMem2, (size_t)_u32Size));
205}
206
213static orxINLINE void * orxMemory_Set(void *_pDest, orxU8 _u8Data, orxU32 _u32Size)
214{
215 /* Checks */
216 orxASSERT(_pDest != orxNULL);
217
218 /* Done! */
219 return((void *)memset(_pDest, _u8Data, (size_t)_u32Size));
220}
221
227static orxINLINE void * orxMemory_Zero(void *_pDest, orxU32 _u32Size)
228{
229 /* Checks */
230 orxASSERT(_pDest != orxNULL);
231
232 /* Done! */
233 return((void *)memset(_pDest, 0, (size_t)_u32Size));
234}
235
236
241extern orxDLLAPI const orxSTRING orxFASTCALL orxMemory_GetTypeName(orxMEMORY_TYPE _eMemType);
242
243
247extern orxDLLAPI orxU32 orxFASTCALL orxMemory_GetCacheLineSize();
248
249
250#ifdef __orxPROFILER__
251
261extern orxDLLAPI orxSTATUS orxFASTCALL orxMemory_GetUsage(orxMEMORY_TYPE _eMemType, orxU64 *_pu64Count, orxU64 *_pu64PeakCount, orxU64 *_pu64Size, orxU64 *_pu64PeakSize, orxU64 *_pu64OperationCount);
262
263
270extern orxDLLAPI orxSTATUS orxFASTCALL orxMemory_Track(orxMEMORY_TYPE _eMemType, orxU32 _u32Size, orxBOOL _bAllocate);
271
272#endif /* __orxPROFILER__ */
273
274#endif /* _orxMEMORY_H_ */
275
#define orxASSERT(TEST,...)
Definition orxDebug.h:378
#define orxDLLAPI
Definition orxDecl.h:381
static orxINLINE orxU32 orxMemory_Compare(const void *_pMem1, const void *_pMem2, orxU32 _u32Size)
Definition orxMemory.h:197
orxDLLAPI orxSTATUS orxFASTCALL orxMemory_InitThread()
orxDLLAPI const orxSTRING orxFASTCALL orxMemory_GetTypeName(orxMEMORY_TYPE _eMemType)
orxDLLAPI void orxFASTCALL orxMemory_ExitThread()
static orxINLINE void * orxMemory_Move(void *_pDest, const void *_pSrc, orxU32 _u32Size)
Definition orxMemory.h:181
orxDLLAPI void orxFASTCALL orxMemory_Free(void *_pMem)
orxDLLAPI void orxFASTCALL orxMemory_Exit()
orxDLLAPI orxU32 orxFASTCALL orxMemory_GetCacheLineSize()
static orxINLINE void * orxMemory_Set(void *_pDest, orxU8 _u8Data, orxU32 _u32Size)
Definition orxMemory.h:213
orxDLLAPI void *orxFASTCALL orxMemory_Reallocate(void *_pMem, orxU32 _u32Size, orxMEMORY_TYPE _eMemType)
orxDLLAPI orxSTATUS orxFASTCALL orxMemory_Init()
orxMEMORY_TYPE
Definition orxMemory.h:95
static orxINLINE void * orxMemory_Zero(void *_pDest, orxU32 _u32Size)
Definition orxMemory.h:227
static orxINLINE void * orxMemory_Copy(void *_pDest, const void *_pSrc, orxU32 _u32Size)
Definition orxMemory.h:165
orxDLLAPI void orxFASTCALL orxMemory_Setup()
orxDLLAPI void *orxFASTCALL orxMemory_Allocate(orxU32 _u32Size, orxMEMORY_TYPE _eMemType)
@ orxMEMORY_TYPE_PHYSICS
Definition orxMemory.h:100
@ orxMEMORY_TYPE_SYSTEM
Definition orxMemory.h:101
@ orxMEMORY_TYPE_VIDEO
Definition orxMemory.h:104
@ orxMEMORY_TYPE_TEXT
Definition orxMemory.h:103
@ orxMEMORY_TYPE_MAIN
Definition orxMemory.h:96
@ orxMEMORY_TYPE_CONFIG
Definition orxMemory.h:98
@ orxMEMORY_TYPE_AUDIO
Definition orxMemory.h:97
@ orxMEMORY_TYPE_TEMP
Definition orxMemory.h:102
@ orxMEMORY_TYPE_NUMBER
Definition orxMemory.h:106
@ orxMEMORY_TYPE_NONE
Definition orxMemory.h:108
@ orxMEMORY_TYPE_DEBUG
Definition orxMemory.h:99
orxSTATUS
Definition orxType.h:270

Generated for orx by doxygen 1.8.11