memoryUsagePointers.h 2.6 KB

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