Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/express/memoryUsage.I

Go to the documentation of this file.
00001 // Filename: memoryUsage.I
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 
00020 ////////////////////////////////////////////////////////////////////
00021 //     Function: MemoryUsage::track_memory_usage
00022 //       Access: Public, Static
00023 //  Description: Returns true if the user has Configured the variable
00024 //               'track-memory-usage' to true, indicating that this
00025 //               class will be in effect.  If this returns false, the
00026 //               user has indicated not to do any of this.
00027 ////////////////////////////////////////////////////////////////////
00028 INLINE bool MemoryUsage::
00029 get_track_memory_usage() {
00030   return get_global_ptr()->_track_memory_usage;
00031 }
00032 
00033 #ifndef __GNUC__
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //     Function: MemoryUsage::record_pointer
00037 //       Access: Public, Static
00038 //  Description: Indicates that the given pointer has been recently
00039 //               allocated.
00040 ////////////////////////////////////////////////////////////////////
00041 INLINE void MemoryUsage::
00042 record_pointer(ReferenceCount *ptr) {
00043   get_global_ptr()->ns_record_pointer(ptr);
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //     Function: MemoryUsage::update_type
00048 //       Access: Public, Static
00049 //  Description: Associates the indicated type with the given pointer.
00050 //               This should be called by functions (e.g. the
00051 //               constructor) that know more specifically what type of
00052 //               thing we've got; otherwise, the MemoryUsage database
00053 //               will know only that it's a "ReferenceCount".
00054 ////////////////////////////////////////////////////////////////////
00055 INLINE void MemoryUsage::
00056 update_type(ReferenceCount *ptr, TypeHandle type) {
00057   get_global_ptr()->ns_update_type(ptr, type);
00058 }
00059 
00060 ////////////////////////////////////////////////////////////////////
00061 //     Function: MemoryUsage::update_type
00062 //       Access: Public, Static
00063 //  Description: Associates the indicated type with the given pointer.
00064 //               This flavor of update_type() also passes in the
00065 //               pointer as a TypedObject, and useful for objects that
00066 //               are, in fact, TypedObjects.  Once the MemoryUsage
00067 //               database has the pointer as a TypedObject it doesn't
00068 //               need any more help.
00069 ////////////////////////////////////////////////////////////////////
00070 INLINE void MemoryUsage::
00071 update_type(ReferenceCount *ptr, TypedObject *typed_ptr) {
00072   get_global_ptr()->ns_update_type(ptr, typed_ptr);
00073 }
00074 
00075 ////////////////////////////////////////////////////////////////////
00076 //     Function: MemoryUsage::remove_pointer
00077 //       Access: Public, Static
00078 //  Description: Indicates that the given pointer has been recently
00079 //               freed.
00080 ////////////////////////////////////////////////////////////////////
00081 INLINE void MemoryUsage::
00082 remove_pointer(ReferenceCount *ptr) {
00083   get_global_ptr()->ns_remove_pointer(ptr);
00084 }
00085 
00086 #endif  // __GNUC__
00087 
00088 ////////////////////////////////////////////////////////////////////
00089 //     Function: MemoryUsage::is_tracking
00090 //       Access: Public, Static
00091 //  Description: Returns true if the MemoryUsage object is currently
00092 //               tracking memory (e.g. track-memory-usage is
00093 //               configured #t).
00094 ////////////////////////////////////////////////////////////////////
00095 INLINE bool MemoryUsage::
00096 is_tracking() {
00097   return get_global_ptr()->_track_memory_usage;
00098 }
00099 
00100 ////////////////////////////////////////////////////////////////////
00101 //     Function: MemoryUsage::is_counting
00102 //       Access: Public, Static
00103 //  Description: Returns true if the MemoryUsage object is currently
00104 //               at least counting memory (e.g. count-memory-usage is
00105 //               configured #t), even if it's not fully tracking it.
00106 ////////////////////////////////////////////////////////////////////
00107 INLINE bool MemoryUsage::
00108 is_counting() {
00109   return get_global_ptr()->_count_memory_usage;
00110 }
00111 
00112 ////////////////////////////////////////////////////////////////////
00113 //     Function: MemoryUsage::get_current_cpp_size
00114 //       Access: Public, Static
00115 //  Description: Returns the total number of bytes of allocated memory
00116 //               via the C++ operators new and delete as counted,
00117 //               not including the memory previously frozen.
00118 ////////////////////////////////////////////////////////////////////
00119 INLINE size_t MemoryUsage::
00120 get_current_cpp_size() {
00121   return get_global_ptr()->ns_get_current_cpp_size();
00122 }
00123 
00124 ////////////////////////////////////////////////////////////////////
00125 //     Function: MemoryUsage::has_cpp_size
00126 //       Access: Public, Static
00127 //  Description: Returns true if the value returned by
00128 //               get_cpp_size() is meaningful on this particular
00129 //               system with this particular configuration, false
00130 //               otherwise.
00131 ////////////////////////////////////////////////////////////////////
00132 INLINE bool MemoryUsage::
00133 has_cpp_size() {
00134 #if defined(WIN32_VC) && defined(_DEBUG)
00135   // Windows in debug mode can count C++ size without having to do a
00136   // full track.
00137   return is_counting();
00138 #else
00139   // Other systems require the full hammer.
00140   return is_tracking();
00141 #endif
00142 }
00143 
00144 ////////////////////////////////////////////////////////////////////
00145 //     Function: MemoryUsage::get_cpp_size
00146 //       Access: Public, Static
00147 //  Description: Returns the total number of bytes of allocated memory
00148 //               via the C++ operators new and delete as counted,
00149 //               including the memory previously frozen.
00150 ////////////////////////////////////////////////////////////////////
00151 INLINE size_t MemoryUsage::
00152 get_cpp_size() {
00153   return get_global_ptr()->ns_get_cpp_size();
00154 }
00155 
00156 ////////////////////////////////////////////////////////////////////
00157 //     Function: MemoryUsage::has_interpreter_size
00158 //       Access: Public, Static
00159 //  Description: Returns true if the value returned by
00160 //               get_interpreter_size() is meaningful on this particular
00161 //               system with this particular configuration, false
00162 //               otherwise.
00163 ////////////////////////////////////////////////////////////////////
00164 INLINE bool MemoryUsage::
00165 has_interpreter_size() {
00166 #ifdef TRACK_IN_INTERPRETER
00167   return is_counting();
00168 #else
00169   return false;
00170 #endif
00171 }
00172 
00173 ////////////////////////////////////////////////////////////////////
00174 //     Function: MemoryUsage::get_interpreter_size
00175 //       Access: Public, Static
00176 //  Description: Returns the total number of bytes of allocated memory
00177 //               while the high-level languange code is running.  This
00178 //               number is only meaningful if both Panda and the
00179 //               high-level language are single-threaded, and running
00180 //               in the same thread.
00181 ////////////////////////////////////////////////////////////////////
00182 INLINE size_t MemoryUsage::
00183 get_interpreter_size() {
00184   return get_global_ptr()->ns_get_interpreter_size();
00185 }
00186 
00187 ////////////////////////////////////////////////////////////////////
00188 //     Function: MemoryUsage::has_total_size
00189 //       Access: Public, Static
00190 //  Description: Returns true if the value returned by
00191 //               get_total_size() is meaningful on this particular
00192 //               system with this particular configuration, false
00193 //               otherwise.
00194 ////////////////////////////////////////////////////////////////////
00195 INLINE bool MemoryUsage::
00196 has_total_size() {
00197 #if defined(WIN32_VC) && defined(_DEBUG)
00198   // Windows in debug mode can count total size without having to do a
00199   // full track.
00200   return is_counting();
00201 #else
00202   // Other systems require the full hammer.
00203   return is_tracking();
00204 #endif
00205 }
00206 
00207 ////////////////////////////////////////////////////////////////////
00208 //     Function: MemoryUsage::get_total_size
00209 //       Access: Public, Static
00210 //  Description: Returns the total size of the dynamic heap, as nearly
00211 //               as can be determined, including all allocated memory
00212 //               if possible, in addition to that tracked by
00213 //               get_cpp_size().
00214 ////////////////////////////////////////////////////////////////////
00215 INLINE size_t MemoryUsage::
00216 get_total_size() {
00217   return get_global_ptr()->ns_get_total_size();
00218 }
00219 
00220 ////////////////////////////////////////////////////////////////////
00221 //     Function: MemoryUsage::get_num_pointers
00222 //       Access: Public, Static
00223 //  Description: Returns the number of pointers currently active.
00224 ////////////////////////////////////////////////////////////////////
00225 INLINE int MemoryUsage::
00226 get_num_pointers() {
00227   return get_global_ptr()->ns_get_num_pointers();
00228 }
00229 
00230 ////////////////////////////////////////////////////////////////////
00231 //     Function: MemoryUsage::get_pointers
00232 //       Access: Public, Static
00233 //  Description: Fills the indicated MemoryUsagePointers with the set
00234 //               of all pointers currently active.
00235 ////////////////////////////////////////////////////////////////////
00236 INLINE void MemoryUsage::
00237 get_pointers(MemoryUsagePointers &result) {
00238   get_global_ptr()->ns_get_pointers(result);
00239 }
00240 
00241 ////////////////////////////////////////////////////////////////////
00242 //     Function: MemoryUsage::get_pointers_of_type
00243 //       Access: Public, Static
00244 //  Description: Fills the indicated MemoryUsagePointers with the set
00245 //               of all pointers of the indicated type currently
00246 //               active.
00247 ////////////////////////////////////////////////////////////////////
00248 INLINE void MemoryUsage::
00249 get_pointers_of_type(MemoryUsagePointers &result, TypeHandle type) {
00250   get_global_ptr()->ns_get_pointers_of_type(result, type);
00251 }
00252 
00253 ////////////////////////////////////////////////////////////////////
00254 //     Function: MemoryUsage::get_pointers_of_age
00255 //       Access: Public, Static
00256 //  Description: Fills the indicated MemoryUsagePointers with the set
00257 //               of all pointers that were allocated within the range
00258 //               of the indicated number of seconds ago.
00259 ////////////////////////////////////////////////////////////////////
00260 INLINE void MemoryUsage::
00261 get_pointers_of_age(MemoryUsagePointers &result, double from, double to) {
00262   get_global_ptr()->ns_get_pointers_of_age(result, from, to);
00263 }
00264 
00265 ////////////////////////////////////////////////////////////////////
00266 //     Function: MemoryUsage::get_pointers_with_zero_count
00267 //       Access: Public, Static
00268 //  Description: Fills the indicated MemoryUsagePointers with the set
00269 //               of all currently active pointers (that is, pointers
00270 //               allocated since the last call to freeze(), and not
00271 //               yet freed) that have a zero reference count.
00272 //
00273 //               Generally, an undeleted pointer with a zero reference
00274 //               count means its reference count has never been
00275 //               incremented beyond zero (since once it has been
00276 //               incremented, the only way it can return to zero would
00277 //               free the pointer).  This may include objects that are
00278 //               allocated statically or on the stack, which are never
00279 //               intended to be deleted.  Or, it might represent a
00280 //               programmer or compiler error.
00281 //
00282 //               This function has the side-effect of incrementing
00283 //               each of their reference counts by one, thus
00284 //               preventing them from ever being freed--but since they
00285 //               hadn't been freed anyway, probably no additional harm
00286 //               is done.
00287 ////////////////////////////////////////////////////////////////////
00288 INLINE void MemoryUsage::
00289 get_pointers_with_zero_count(MemoryUsagePointers &result) {
00290   get_global_ptr()->ns_get_pointers_with_zero_count(result);
00291 }
00292 
00293 ////////////////////////////////////////////////////////////////////
00294 //     Function: MemoryUsage::freeze
00295 //       Access: Public, Static
00296 //  Description: 'Freezes' all pointers currently stored so that they
00297 //               are no longer reported; only newly allocate pointers
00298 //               from this point on will appear in future information
00299 //               requests.  This makes it easier to differentiate
00300 //               between continuous leaks and one-time memory
00301 //               allocations.
00302 ////////////////////////////////////////////////////////////////////
00303 INLINE void MemoryUsage::
00304 freeze() {
00305   get_global_ptr()->ns_freeze();
00306 }
00307 
00308 ////////////////////////////////////////////////////////////////////
00309 //     Function: MemoryUsage::show_current_types
00310 //       Access: Public, Static
00311 //  Description: Shows the breakdown of types of all of the
00312 //               active pointers.
00313 ////////////////////////////////////////////////////////////////////
00314 INLINE void MemoryUsage::
00315 show_current_types() {
00316   get_global_ptr()->ns_show_current_types();
00317 }
00318 
00319 ////////////////////////////////////////////////////////////////////
00320 //     Function: MemoryUsage::show_trend_types
00321 //       Access: Public, Static
00322 //  Description: Shows the breakdown of types of all of the
00323 //               pointers allocated and freed since the last call to
00324 //               freeze().
00325 ////////////////////////////////////////////////////////////////////
00326 INLINE void MemoryUsage::
00327 show_trend_types() {
00328   get_global_ptr()->ns_show_trend_types();
00329 }
00330 
00331 ////////////////////////////////////////////////////////////////////
00332 //     Function: MemoryUsage::show_current_ages
00333 //       Access: Public, Static
00334 //  Description: Shows the breakdown of ages of all of the
00335 //               active pointers.
00336 ////////////////////////////////////////////////////////////////////
00337 INLINE void MemoryUsage::
00338 show_current_ages() {
00339   get_global_ptr()->ns_show_current_ages();
00340 }
00341 
00342 ////////////////////////////////////////////////////////////////////
00343 //     Function: MemoryUsage::show_trend_ages
00344 //       Access: Public, Static
00345 //  Description: Shows the breakdown of ages of all of the
00346 //               pointers allocated and freed since the last call to
00347 //               freeze().
00348 ////////////////////////////////////////////////////////////////////
00349 INLINE void MemoryUsage::
00350 show_trend_ages() {
00351   get_global_ptr()->ns_show_trend_ages();
00352 }

Generated on Fri May 2 00:38:25 2003 for Panda by doxygen1.3