daeMemorySystem.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2006 Sony Computer Entertainment Inc.
  3. *
  4. * Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
  5. * file except in compliance with the License. You may obtain a copy of the License at:
  6. * http://research.scea.com/scea_shared_source_license.html
  7. *
  8. * Unless required by applicable law or agreed to in writing, software distributed under the License
  9. * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  10. * implied. See the License for the specific language governing permissions and limitations under the
  11. * License.
  12. */
  13. #ifndef __DAE_MEMORY_SYSTEM_H__
  14. #define __DAE_MEMORY_SYSTEM_H__
  15. #include <dae/daeTypes.h>
  16. /**
  17. * The @c daeMemorySystem class is a simple wrapper for memory operations.
  18. * Every allocation passes a string pool name such that
  19. * in the future different pools can be used based on allocation type.
  20. * Currently the system is just a pass-through to system @c malloc.
  21. */
  22. class daeMemorySystem
  23. {
  24. public:
  25. /**
  26. * Provides a wrapper malloc with pool field.
  27. * @param pool String name of the pool to use for this allocation.
  28. * @param n Number of bytes to allocate.
  29. * @return Returns the memory allocated if successful, or NULL if not.
  30. */
  31. static DLLSPEC daeRawRef alloc(daeString pool, size_t n);
  32. /**
  33. * Provides a wrapper free with pool argument.
  34. * @param pool Pool the memory should be freed from.
  35. * @param mem Memory to be freed.
  36. */
  37. static DLLSPEC void dealloc(daeString pool, daeRawRef mem);
  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. #if 0
  45. #define DAE_ALLOC \
  46. /* Standard new/delete */ \
  47. inline void* operator new(size_t size) { return daeMemorySystem::alloc("meta", size); } \
  48. inline void operator delete(void* p) { daeMemorySystem::dealloc("meta", p); } \
  49. /* Placement new/delete */ \
  50. inline void* operator new(size_t, void* p) { return p; } \
  51. inline void operator delete(void*, void*) { }
  52. #endif
  53. #define DAE_ALLOC
  54. #endif // __DAE_MEMORY_H__