~ubuntu-branches/ubuntu/oneiric/nux/oneiric-proposed

« back to all changes in this revision

Viewing changes to NuxCore/Memory.h

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2011-07-04 18:34:48 UTC
  • mfrom: (1.1.22 upstream)
  • Revision ID: james.westby@ubuntu.com-20110704183448-wzm2936r4xyob3d9
Tags: 1.0.4-0ubuntu1
* New upstream release.
* debian/rules:
  - bump shlib

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
#define NUX_SAFE_DELETE(mem)    if(mem)             \
29
29
                                {                   \
30
 
                                    INLDELETE (mem);   \
 
30
                                    delete(mem);    \
31
31
                                    (mem) = 0;      \
32
32
                                }
33
33
#define NUX_SAFE_DELETE_ARRAY(mem_array)    if(mem_array)               \
34
34
                                            {                           \
35
 
                                                INLDELETEARRAY (mem_array);  \
 
35
                                                delete[](mem_array);    \
36
36
                                                (mem_array) = 0;        \
37
37
                                            }
38
38
 
39
 
#define NUX_SAFE_FREE(mem)    if(mem)             \
40
 
{                   \
41
 
    std::free(mem);      \
42
 
    (mem) = 0;      \
43
 
}
44
 
 
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
59
 
#endif
60
39
 
61
40
namespace nux
62
41
{
83
62
 
84
63
}
85
64
 
86
 
inline void inlFree ( void *Original )
87
 
{
88
 
  return free ( Original );
89
 
}
90
 
 
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
98
 
 
99
 
 
100
 
#define NUX_NEW_EXPLICIT(Allocator, ClassName, Comment, ParentPtr, File, Line, FunctionName)    \
101
 
        new(Memory::MemHelperAlloc< ClassName >(NUX_MEMOP_NEW,                 \
102
 
                    1,                                                              \
103
 
                    Allocator,                                                      \
104
 
                    ParentPtr,                                                      \
105
 
                    Comment,                                                        \
106
 
                    #ClassName,                                                     \
107
 
                    File,                                                           \
108
 
                    Line,                                                           \
109
 
                    FunctionName)) ClassName
110
 
 
111
 
 
112
 
 
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)
115
 
 
116
 
#define NUX_DELETE_EXPLICIT(ptrObject, File, Line, FunctionName)                \
117
 
        Memory::MemHelperDelete(NUX_MEMOP_DELETE, (ptrObject),                 \
118
 
                          File,                                                     \
119
 
                          Line,                                                     \
120
 
                          FunctionName);
121
 
#define NUX_DELETE(ptrObject)     NUX_DELETE_EXPLICIT(ptrObject, __FILE__, __LINE__, __FUNCTION__)
122
 
#define inlDelete(ptrObject) NUX_DELETE(ptrObject)
123
 
 
124
 
 
125
 
 
126
 
#define NUX_ALLOC_EXPLICIT(Allocator, ObjectType, Count, Comment, ParentPtr, File, Line, FunctionName)      \
127
 
        Memory::MemHelperAlloc< ObjectType >(NUX_MEMOP_ALLOC,                                              \
128
 
                                              Count,                                                            \
129
 
                                              Allocator,                                                        \
130
 
                                              ParentPtr,                                                        \
131
 
                                              Comment,                                                          \
132
 
                                              #ObjectType,                                                      \
133
 
                                              File,                                                             \
134
 
                                              Line,                                                             \
135
 
                                              FunctionName)
136
 
 
137
 
 
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__)
140
 
 
141
 
 
142
 
#define NUX_FREE_EXPLICIT(Allocator, Ptr, File, Line)       \
143
 
        Memory::MemHelperFastDelete( NUX_MEMOP_FREE,       \
144
 
                            Allocator,                          \
145
 
                            Ptr,                                \
146
 
                            File,                               \
147
 
                            Line);
148
 
 
149
 
#define NUX_FREE(Allocator, Ptr)     NUX_FREE_EXPLICIT(Allocator, Ptr, __FILE__, __LINE__)
150
 
#define inlMMFree(Allocator, Ptr)      NUX_FREE(Allocator, Ptr)
151
 
 
152
65
#endif // NMEMORY_H