dallocator.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Filename: dallocator.h
  2. // Created by: drose (05Jun01)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef DALLOCATOR_H
  19. #define DALLOCATOR_H
  20. #include <memory>
  21. #include "dtoolbase.h"
  22. ////////////////////////////////////////////////////////////////////
  23. // Class : dallocator
  24. // Description : This is similar to pallocator, but always uses the
  25. // default new and delete handlers defined in
  26. // dtoolbase_cc.h; it never calls the hooks assigned by
  27. // redefining global_operator_new, etc.
  28. //
  29. // This is needed in those rare cases when we need to
  30. // allocate memory for STL without going through the
  31. // callback hooks, for instance to implement STL tables
  32. // within the MemoryUsage class itself.
  33. ////////////////////////////////////////////////////////////////////
  34. #if defined(NO_STYLE_ALLOCATOR)
  35. // If we're not trying to make custom allocators (either we don't know
  36. // what kind of syntax this STL library wants, or we're compiling with
  37. // OPTIMIZE 4), then simply use the standard allocator.
  38. #define dallocator allocator
  39. #elif defined(OLD_STYLE_ALLOCATOR)
  40. // Early versions of gcc wanted to use their own kind of allocator,
  41. // somewhat different from the STL standard. Irix uses this one too.
  42. // It might be inherited from an early draft of the STL standard.
  43. template<class Type>
  44. class dallocator : public alloc {
  45. public:
  46. INLINE static Type *allocate(size_t n);
  47. INLINE static void deallocate(void *p, size_t n);
  48. };
  49. #elif defined(GNU_STYLE_ALLOCATOR)
  50. // Later versions of gcc want to use a still different,
  51. // not-quite-standard definition. Sheesh.
  52. template<class Type>
  53. class dallocator : public allocator<Type> {
  54. public:
  55. INLINE dallocator();
  56. template<class _Tp1>
  57. INLINE dallocator(const dallocator<_Tp1> &other);
  58. INLINE Type *allocate(size_t n);
  59. INLINE void deallocate(void *p, size_t n);
  60. template <class _Tp1> struct rebind {
  61. typedef dallocator<_Tp1> other;
  62. };
  63. };
  64. #elif defined(MODERN_STYLE_ALLOCATOR)
  65. // The final specification?
  66. template<class Type>
  67. class dallocator : public allocator<Type> {
  68. public:
  69. INLINE dallocator() throw();
  70. // template member functions in VC++ can only be defined in-class.
  71. template<class U>
  72. INLINE dallocator(const dallocator<U> &copy) throw() { }
  73. INLINE pointer allocate(size_type n, allocator<void>::const_pointer hint = 0);
  74. INLINE void deallocate(void *p, size_type n);
  75. template<class U> struct rebind {
  76. typedef dallocator<U> other;
  77. };
  78. };
  79. #else
  80. #error Unrecognized allocator symbol defined!
  81. #endif // *_STYLE_ALLOCATOR
  82. #ifndef NO_STYLE_ALLOCATOR
  83. #include "dallocator.T"
  84. #endif
  85. #endif