2
* Copyright 2010 Inalogic Inc.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3, as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the applicable version of the GNU Lesser General Public
12
* License for more details.
14
* You should have received a copy of both the GNU Lesser General Public
15
* License version 3 along with this program. If not, see
16
* <http://www.gnu.org/licenses/>
18
* Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
26
#define NUX_DEFAULT_ALIGNMENT 4
28
#define NUX_SAFE_DELETE(mem) if(mem) \
33
#define NUX_SAFE_DELETE_ARRAY(mem_array) if(mem_array) \
35
INLDELETEARRAY (mem_array); \
39
#define NUX_SAFE_FREE(mem) if(mem) \
45
#if defined(NUX_OS_WINDOWS)
46
#define NUX_SYS_MEMORY_MALLOC(size) malloc(size)
47
#define NUX_SYS_MEMORY_MEM_ALIGN(align, size) NUX_SYS_MEMORY_MALLOC(size)
48
#define NUX_SYS_MEMORY_REALLOC(ptr, size) realloc(ptr, size)
49
#define NUX_SYS_MEMORY_REALLOC_ALIGN(ptr, size, align) realloc(ptr, size)
50
#define NUX_SYS_MEMORY_FREE(ptr) free(ptr)
51
#define NUX_SYS_MEMORY_PTR_SIZE(ptr) _msize(ptr)
52
#elif defined(NUX_OS_LINUX)
53
#define NUX_SYS_MEMORY_MALLOC(size) malloc(size)
54
#define NUX_SYS_MEMORY_MEM_ALIGN(align, size) NUX_SYS_MEMORY_MALLOC(size)
55
#define NUX_SYS_MEMORY_REALLOC(ptr, size) realloc(ptr, size)
56
#define NUX_SYS_MEMORY_REALLOC_ALIGN(ptr, size, align) realloc(ptr, size)
57
#define NUX_SYS_MEMORY_FREE(ptr) free(ptr)
58
#define NUX_SYS_MEMORY_PTR_SIZE(ptr) 0
64
t_u32 Memcmp ( const void *Buf1, const void *Buf2, t_u32 Count );
66
bool MemIsZero ( const void *V, t_size Count );
68
void *Memmove ( void *Dest, const void *Src, t_size Count );
70
void Memset ( void *Dest, t_s32 C, t_size Count );
72
void Memzero ( void *Dest, t_size Count );
74
void Memcpy ( void *Dest, const void *Src, t_size Count );
76
void Memswap ( void *Ptr1, void *Ptr2, t_size Size );
78
//! Check that the alignment is a power of two
79
bool IsMemoryAligned (void *data, t_u32 alignment);
81
void *Malloc (t_size Count, t_u32 Alignment = NUX_DEFAULT_ALIGNMENT);
82
void *Realloc (void *Original, t_size Count, t_u32 Alignment = NUX_DEFAULT_ALIGNMENT);
86
inline void inlFree ( void *Original )
88
return free ( Original );
91
/// Memory operation defines
92
#define NUX_MEMOP_ALLOC 1
93
#define NUX_MEMOP_NEW 2
94
#define NUX_MEMOP_NEWARRAY 3
95
#define NUX_MEMOP_FREE 4
96
#define NUX_MEMOP_DELETE 5
97
#define NUX_MEMOP_DELETEARRAY 6
100
#define NUX_NEW_EXPLICIT(Allocator, ClassName, Comment, ParentPtr, File, Line, FunctionName) \
101
new(Memory::MemHelperAlloc< ClassName >(NUX_MEMOP_NEW, \
109
FunctionName)) ClassName
113
#define NUX_NEW(Allocator, ClassName, Comment, ParentPtr) NUX_NEW_EXPLICIT(Allocator, ClassName, Comment, ParentPtr, __FILE__, __LINE__, __FUNCTION__)
114
#define inlNew(ClassName, Comment, ParentPtr) NUX_NEW(GetDefaultMemoryAllocator(), ClassName, Comment, ParentPtr)
116
#define NUX_DELETE_EXPLICIT(ptrObject, File, Line, FunctionName) \
117
Memory::MemHelperDelete(NUX_MEMOP_DELETE, (ptrObject), \
121
#define NUX_DELETE(ptrObject) NUX_DELETE_EXPLICIT(ptrObject, __FILE__, __LINE__, __FUNCTION__)
122
#define inlDelete(ptrObject) NUX_DELETE(ptrObject)
126
#define NUX_ALLOC_EXPLICIT(Allocator, ObjectType, Count, Comment, ParentPtr, File, Line, FunctionName) \
127
Memory::MemHelperAlloc< ObjectType >(NUX_MEMOP_ALLOC, \
138
#define NUX_ALLOC(Allocator, ObjectType, Count, Comment, ParentPtr, File, Line, FunctionName) NUX_ALLOC_EXPLICIT(Allocator, ObjectType, Count, Comment, ParentPtr, File, Line, FunctionName)
139
#define inlMMAlloc(Allocator, ObjectType, Count, Comment, ParentPtr) NUX_ALLOC(Allocator, ObjectType, Count, Comment, ParentPtr, __FILE__, __LINE__, __FUNCTION__)
142
#define NUX_FREE_EXPLICIT(Allocator, Ptr, File, Line) \
143
Memory::MemHelperFastDelete( NUX_MEMOP_FREE, \
149
#define NUX_FREE(Allocator, Ptr) NUX_FREE_EXPLICIT(Allocator, Ptr, __FILE__, __LINE__)
150
#define inlMMFree(Allocator, Ptr) NUX_FREE(Allocator, Ptr)