Newton Dynamics  4.00
ndMemory.h
1 /* Copyright (c) <2003-2022> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 #ifndef __ND_MEMORY_H__
23 #define __ND_MEMORY_H__
24 
25 #include "ndCoreStdafx.h"
26 #include "ndTypes.h"
27 
28 typedef void* (*ndMemAllocCallback) (size_t size);
29 typedef void (*ndMemFreeCallback) (void* const ptr);
30 
31 class ndMemory
32 {
33  public:
37  D_CORE_API static void* Malloc(size_t size);
38 
40  D_CORE_API static void Free(void* const ptr);
41 
43  D_CORE_API static ndInt32 GetSize(void* const ptr);
44 
46  D_CORE_API static ndInt32 CalculateBufferSize(size_t size);
47 
49  D_CORE_API static ndUnsigned64 GetMemoryUsed();
50 
64  D_CORE_API static void SetMemoryAllocators(ndMemAllocCallback alloc, ndMemFreeCallback free);
65  D_CORE_API static void GetMemoryAllocators(ndMemAllocCallback& alloc, ndMemFreeCallback& free);
66 
67  private:
68  static ndAtomic<ndUnsigned64> m_memoryUsed;
69 };
70 
71 #endif
ndMemory::Malloc
static D_CORE_API void * Malloc(size_t size)
General Memory allocation function.
Definition: ndMemory.cpp:46
ndMemory::GetSize
static D_CORE_API ndInt32 GetSize(void *const ptr)
Get memory buffer size previously allocated by Malloc.
Definition: ndMemory.cpp:71
ndMemory
Definition: ndMemory.h:32
ndMemory::SetMemoryAllocators
static D_CORE_API void SetMemoryAllocators(ndMemAllocCallback alloc, ndMemFreeCallback free)
Install low level system memory allocation functions.
Definition: ndMemory.cpp:82
ndMemory::GetMemoryUsed
static D_CORE_API ndUnsigned64 GetMemoryUsed()
Return the total memory allocated by the newton engine and tools.
Definition: ndMemory.cpp:77
ndMemory::CalculateBufferSize
static D_CORE_API ndInt32 CalculateBufferSize(size_t size)
Calculate buffer size.
Definition: ndMemory.cpp:41
ndAtomic< ndUnsigned64 >
ndMemory::Free
static D_CORE_API void Free(void *const ptr)
Destroy a memory buffer previously allocated by Malloc.
Definition: ndMemory.cpp:61