1 | #ifndef NX_FOUNDATION_NXUSER_ALLOCATOR_DEFAULT
|
---|
2 | #define NX_FOUNDATION_NXUSER_ALLOCATOR_DEFAULT
|
---|
3 | /*----------------------------------------------------------------------------*\
|
---|
4 | |
|
---|
5 | | NovodeX Technology
|
---|
6 | |
|
---|
7 | | www.novodex.com
|
---|
8 | |
|
---|
9 | \*----------------------------------------------------------------------------*/
|
---|
10 | /** \addtogroup foundation
|
---|
11 | @{
|
---|
12 | */
|
---|
13 |
|
---|
14 | #include "NxUserAllocator.h"
|
---|
15 | #include "Nx.h"
|
---|
16 |
|
---|
17 | #include <stdlib.h>
|
---|
18 |
|
---|
19 | #if defined(WIN32) && NX_DEBUG_MALLOC
|
---|
20 | #include <crtdbg.h>
|
---|
21 | #endif
|
---|
22 |
|
---|
23 | /**
|
---|
24 | \brief Default implementation of memory allocator using standard C malloc / free / realloc.
|
---|
25 |
|
---|
26 | See #NxUserAllocator
|
---|
27 | */
|
---|
28 | class NxUserAllocatorDefault : public NxUserAllocator
|
---|
29 | {
|
---|
30 | public:
|
---|
31 | /**
|
---|
32 | \brief Allocates size bytes of memory.
|
---|
33 |
|
---|
34 | Compatible with the standard C malloc().
|
---|
35 | */
|
---|
36 | void* malloc(size_t size, NxMemoryType type)
|
---|
37 | {
|
---|
38 | return ::malloc(size);
|
---|
39 | }
|
---|
40 | void* malloc(size_t size)
|
---|
41 | {
|
---|
42 | return ::malloc(size);
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | \brief Allocates size bytes of memory.
|
---|
47 |
|
---|
48 | Same as above, but with extra debug info fields.
|
---|
49 | */
|
---|
50 | void* mallocDEBUG(size_t size, const char* fileName, int line, const char* className, NxMemoryType type)
|
---|
51 | {
|
---|
52 | #ifdef _DEBUG
|
---|
53 | #if defined(WIN32) && NX_DEBUG_MALLOC
|
---|
54 | return ::_malloc_dbg(size, _NORMAL_BLOCK, fileName, line);
|
---|
55 | #else
|
---|
56 | return ::malloc(size);
|
---|
57 | #endif
|
---|
58 | #else
|
---|
59 | NX_ASSERT(0);//Don't use debug malloc for release mode code!
|
---|
60 | return 0;
|
---|
61 | #endif
|
---|
62 | }
|
---|
63 | void* mallocDEBUG(size_t size, const char* fileName, int line)
|
---|
64 | {
|
---|
65 | #ifdef _DEBUG
|
---|
66 | #if defined(WIN32) && NX_DEBUG_MALLOC
|
---|
67 | return ::_malloc_dbg(size, _NORMAL_BLOCK, fileName, line);
|
---|
68 | #else
|
---|
69 | return ::malloc(size);
|
---|
70 | #endif
|
---|
71 | #else
|
---|
72 | NX_ASSERT(0);//Don't use debug malloc for release mode code!
|
---|
73 | return 0;
|
---|
74 | #endif
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | \brief Resizes the memory block previously allocated with malloc() or
|
---|
79 | realloc() to be size() bytes, and returns the possibly moved memory.
|
---|
80 |
|
---|
81 | Compatible with the standard C realloc().
|
---|
82 | */
|
---|
83 | void* realloc(void* memory, size_t size)
|
---|
84 | {
|
---|
85 | return ::realloc(memory,size);
|
---|
86 | }
|
---|
87 |
|
---|
88 | /**
|
---|
89 | \brief Frees the memory previously allocated by malloc() or realloc().
|
---|
90 |
|
---|
91 | Compatible with the standard C free().
|
---|
92 | */
|
---|
93 | void free(void* memory)
|
---|
94 | {
|
---|
95 | ::free(memory);
|
---|
96 | }
|
---|
97 |
|
---|
98 | void check()
|
---|
99 | {
|
---|
100 | #if defined(WIN32) && defined(_DEBUG)
|
---|
101 | _CrtCheckMemory();
|
---|
102 | #endif
|
---|
103 | }
|
---|
104 | };
|
---|
105 |
|
---|
106 | /** @} */
|
---|
107 | #endif
|
---|
108 |
|
---|
109 |
|
---|
110 | //AGCOPYRIGHTBEGIN
|
---|
111 | ///////////////////////////////////////////////////////////////////////////
|
---|
112 | // Copyright © 2005 AGEIA Technologies.
|
---|
113 | // All rights reserved. www.ageia.com
|
---|
114 | ///////////////////////////////////////////////////////////////////////////
|
---|
115 | //AGCOPYRIGHTEND
|
---|
116 |
|
---|