Panda3D
memoryUsagePointers.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file memoryUsagePointers.h
10  * @author drose
11  * @date 2000-05-25
12  */
13 
14 #ifndef MEMORYUSAGEPOINTERS_H
15 #define MEMORYUSAGEPOINTERS_H
16 
17 #include "pandabase.h"
18 #include "typedObject.h"
19 #include "pointerTo.h"
20 #include "referenceCount.h"
21 #include "pvector.h"
22 
23 /**
24  * This is a list of pointers returned by a MemoryUsage object in response to
25  * some query.
26  *
27  * Warning: once pointers are stored in a MemoryUsagePointers object, they are
28  * reference-counted, and will not be freed until the MemoryUsagePointers
29  * object is freed (or clear() is called on the object). However, they may
30  * not even be freed then; pointers may leak once they have been added to this
31  * structure. This is because we don't store enough information in this
32  * structure to correctly free the pointers that have been added. Since this
33  * is intended primarily as a debugging tool, this is not a major issue.
34  *
35  * This class is just a user interface to talk about pointers stored in a
36  * MemoryUsage object. It doesn't even exist when compiled with NDEBUG.
37  */
38 class EXPCL_PANDA_EXPRESS MemoryUsagePointers {
39 PUBLISHED:
42 
43  size_t get_num_pointers() const;
44  ReferenceCount *get_pointer(size_t n) const;
45  MAKE_SEQ(get_pointers, get_num_pointers, get_pointer);
46  TypedObject *get_typed_pointer(size_t n) const;
47  MAKE_SEQ(get_typed_pointers, get_num_pointers, get_typed_pointer);
48 
49  TypeHandle get_type(size_t n) const;
50  std::string get_type_name(size_t n) const;
51  double get_age(size_t n) const;
52 
53 #ifdef DO_MEMORY_USAGE
54  EXTENSION(PyObject *get_python_pointer(size_t n) const);
55 #endif
56 
57  void clear();
58 
59  void output(std::ostream &out) const;
60 
61 private:
62  void add_entry(ReferenceCount *ref_ptr, TypedObject *typed_ptr,
63  TypeHandle type, double age);
64 
65  class Entry {
66  public:
67  INLINE Entry(ReferenceCount *ref_ptr, TypedObject *typed_ptr,
68  TypeHandle type, double age);
69  INLINE Entry(const Entry &copy);
70  INLINE void operator = (const Entry &copy);
71  INLINE ~Entry();
72 
73  // We have an ordinary pointer to a type ReferenceCount, and not a
74  // PT(ReferenceCount), because we can't actually delete this thing (since
75  // ReferenceCount has no public destructor). If we can't delete it, we
76  // can't make a PointerTo it, since PointerTo wants to be able to delete
77  // things.
78  ReferenceCount *_ref_ptr;
79  TypedObject *_typed_ptr;
80  TypeHandle _type;
81  double _age;
82  };
83 
84  typedef pvector<Entry> Entries;
85  Entries _entries;
86  friend class MemoryUsage;
87 };
88 
89 INLINE std::ostream &operator << (std::ostream &out, const MemoryUsagePointers &mup) {
90  mup.output(out);
91  return out;
92 }
93 
94 #include "memoryUsagePointers.I"
95 
96 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is an abstract class that all classes which use TypeHandle, and also provide virtual functions t...
Definition: typedObject.h:88
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a list of pointers returned by a MemoryUsage object in response to some query.
This class is used strictly for debugging purposes, specifically for tracking memory leaks of referen...
Definition: memoryUsage.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A base class for all things that want to be reference-counted.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.