memoryUsagePointers.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Filename: memoryUsagePointers.h
  2. // Created by: drose (25May00)
  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 MEMORYUSAGEPOINTERS_H
  19. #define MEMORYUSAGEPOINTERS_H
  20. #include "pandabase.h"
  21. #ifdef DO_MEMORY_USAGE
  22. #include "typedObject.h"
  23. #include "pointerTo.h"
  24. #include "referenceCount.h"
  25. #include "pvector.h"
  26. ////////////////////////////////////////////////////////////////////
  27. // Class : MemoryUsagePointers
  28. // Description : This is a list of pointers returned by a MemoryUsage
  29. // object in response to some query.
  30. //
  31. // Warning: once pointers are stored in a
  32. // MemoryUsagePointers object, they are
  33. // reference-counted, and will not be freed until the
  34. // MemoryUsagePointers object is freed (or clear() is
  35. // called on the object). However, they may not even be
  36. // freed then; pointers may leak once they have been
  37. // added to this structure. This is because we don't
  38. // store enough information in this structure to
  39. // correctly free the pointers that have been added.
  40. // Since this is intended primarily as a debugging tool,
  41. // this is not a major issue.
  42. //
  43. // This class is just a user interface to talk about
  44. // pointers stored in a MemoryUsage object. It doesn't
  45. // even exist when compiled with NDEBUG.
  46. ////////////////////////////////////////////////////////////////////
  47. class EXPCL_PANDAEXPRESS MemoryUsagePointers {
  48. PUBLISHED:
  49. MemoryUsagePointers();
  50. ~MemoryUsagePointers();
  51. int get_num_pointers() const;
  52. ReferenceCount *get_pointer(int n) const;
  53. TypedObject *get_typed_pointer(int n) const;
  54. TypeHandle get_type(int n) const;
  55. string get_type_name(int n) const;
  56. double get_age(int n) const;
  57. void clear();
  58. private:
  59. void add_entry(ReferenceCount *ref_ptr, TypedObject *typed_ptr,
  60. TypeHandle type, double age);
  61. class Entry {
  62. public:
  63. INLINE Entry(ReferenceCount *ref_ptr, TypedObject *typed_ptr,
  64. TypeHandle type, double age);
  65. INLINE Entry(const Entry &copy);
  66. INLINE void operator = (const Entry &copy);
  67. INLINE ~Entry();
  68. // We have an ordinary pointer to a type ReferenceCount, and not a
  69. // PT(ReferenceCount), because we can't actually delete this thing
  70. // (since ReferenceCount has no public destructor). If we can't
  71. // delete it, we can't make a PointerTo it, since PointerTo wants
  72. // to be able to delete things.
  73. ReferenceCount *_ref_ptr;
  74. TypedObject *_typed_ptr;
  75. TypeHandle _type;
  76. double _age;
  77. };
  78. typedef pvector<Entry> Entries;
  79. Entries _entries;
  80. friend class MemoryUsage;
  81. };
  82. #include "memoryUsagePointers.I"
  83. #endif // MEMORY_USAGE_POINTERS
  84. #endif