00001 // Filename: memoryUsagePointers.h 00002 // Created by: drose (25May00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #ifndef MEMORYUSAGEPOINTERS_H 00020 #define MEMORYUSAGEPOINTERS_H 00021 00022 #include "pandabase.h" 00023 00024 #ifdef DO_MEMORY_USAGE 00025 00026 #include "typedObject.h" 00027 #include "pointerTo.h" 00028 #include "referenceCount.h" 00029 #include "pvector.h" 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Class : MemoryUsagePointers 00033 // Description : This is a list of pointers returned by a MemoryUsage 00034 // object in response to some query. 00035 // 00036 // Warning: once pointers are stored in a 00037 // MemoryUsagePointers object, they are 00038 // reference-counted, and will not be freed until the 00039 // MemoryUsagePointers object is freed (or clear() is 00040 // called on the object). However, they may not even be 00041 // freed then; pointers may leak once they have been 00042 // added to this structure. This is because we don't 00043 // store enough information in this structure to 00044 // correctly free the pointers that have been added. 00045 // Since this is intended primarily as a debugging tool, 00046 // this is not a major issue. 00047 // 00048 // This class is just a user interface to talk about 00049 // pointers stored in a MemoryUsage object. It doesn't 00050 // even exist when compiled with NDEBUG. 00051 //////////////////////////////////////////////////////////////////// 00052 class EXPCL_PANDAEXPRESS MemoryUsagePointers { 00053 PUBLISHED: 00054 MemoryUsagePointers(); 00055 ~MemoryUsagePointers(); 00056 00057 int get_num_pointers() const; 00058 ReferenceCount *get_pointer(int n) const; 00059 TypedObject *get_typed_pointer(int n) const; 00060 TypeHandle get_type(int n) const; 00061 string get_type_name(int n) const; 00062 double get_age(int n) const; 00063 00064 void clear(); 00065 00066 private: 00067 void add_entry(ReferenceCount *ref_ptr, TypedObject *typed_ptr, 00068 TypeHandle type, double age); 00069 00070 class Entry { 00071 public: 00072 INLINE Entry(ReferenceCount *ref_ptr, TypedObject *typed_ptr, 00073 TypeHandle type, double age); 00074 INLINE Entry(const Entry ©); 00075 INLINE void operator = (const Entry ©); 00076 INLINE ~Entry(); 00077 00078 // We have an ordinary pointer to a type ReferenceCount, and not a 00079 // PT(ReferenceCount), because we can't actually delete this thing 00080 // (since ReferenceCount has no public destructor). If we can't 00081 // delete it, we can't make a PointerTo it, since PointerTo wants 00082 // to be able to delete things. 00083 ReferenceCount *_ref_ptr; 00084 TypedObject *_typed_ptr; 00085 TypeHandle _type; 00086 double _age; 00087 }; 00088 00089 typedef pvector<Entry> Entries; 00090 Entries _entries; 00091 friend class MemoryUsage; 00092 }; 00093 00094 #include "memoryUsagePointers.I" 00095 00096 #endif // MEMORY_USAGE_POINTERS 00097 00098 #endif 00099