• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright 2006 Sony Computer Entertainment Inc.
3 *
4 * Licensed under the MIT Open Source License, for details please see license.txt or the website
5 * http://www.opensource.org/licenses/mit-license.php
6 *
7 */
8 
9 #ifndef __DAE_MEMORY_SYSTEM_H__
10 #define __DAE_MEMORY_SYSTEM_H__
11 
12 #include <dae/daeTypes.h>
13 
14 /**
15  * The @c daeMemorySystem class is a simple wrapper for memory operations.
16  * Every allocation passes a string pool name such that
17  * in the future different pools can be used based on allocation type.
18  * Currently the system is just a pass-through to system @c malloc.
19  */
20 class daeMemorySystem
21 {
22 public:
23 	/**
24 	 * Provides a wrapper malloc with pool field.
25 	 * @param pool String name of the pool to use for this allocation.
26 	 * @param n Number of bytes to allocate.
27 	 * @return Returns the memory allocated if successful, or NULL if not.
28 	 */
29 	static DLLSPEC daeRawRef alloc(daeString pool, size_t n);
30 
31 	/**
32 	 * Provides a wrapper free with pool argument.
33 	 * @param pool Pool the memory should be freed from.
34 	 * @param mem Memory to be freed.
35 	 */
36 	static DLLSPEC void dealloc(daeString pool, daeRawRef mem);
37 };
38 
39 // (steveT) These new/delete overrides aren't complete. What about new[] and delete[]?
40 // Standard new should throw a bad_alloc exception, and a nothrow new should be provided
41 // that returns null instead of throwing bad_alloc. Because of these problems, plus the
42 // fact that we currently don't benefit in any way from overriding new and delete, this
43 // code is currently disabled.
44 
45 #if 0
46 #define DAE_ALLOC \
47 	/* Standard new/delete */ \
48 	inline void* operator new(size_t size) { return daeMemorySystem::alloc("meta", size); } \
49 	inline void operator delete(void* p) { daeMemorySystem::dealloc("meta", p); } \
50 	/* Placement new/delete */ \
51 	inline void* operator new(size_t, void* p) { return p; } \
52 	inline void operator delete(void*, void*) { }
53 #endif
54 
55 #define DAE_ALLOC
56 
57 #endif // __DAE_MEMORY_H__
58