• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List

malloc.h

00001 /***************************************************************************
00002  *  include/stxxl/bits/utils/malloc.h
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright (C) 2003 Roman Dementiev <[email protected]>
00007  *
00008  *  Distributed under the Boost Software License, Version 1.0.
00009  *  (See accompanying file LICENSE_1_0.txt or copy at
00010  *  http://www.boost.org/LICENSE_1_0.txt)
00011  **************************************************************************/
00012 
00013 #ifndef STXXL_MALLOC_H
00014 #define STXXL_MALLOC_H
00015 
00016 #include <ostream>
00017 #ifdef __FreeBSD__
00018     #include <stdlib.h>
00019 #else
00020     #include <malloc.h>
00021 #endif
00022 #include <cstdlib>
00023 
00024 #include <stxxl/bits/namespace.h>
00025 
00026 
00027 __STXXL_BEGIN_NAMESPACE
00028 
00029 
00031 
00033 class malloc_stats
00034 {
00035 #if !defined(__APPLE__) && !defined(__FreeBSD__)
00036 
00037 public:
00038     typedef int return_type;
00039 
00041     return_type from_system_nmmap() const
00042     {
00043         struct mallinfo info = mallinfo();
00044         return info.arena;
00045     }
00046 
00048     return_type free_chunks() const
00049     {
00050         struct mallinfo info = mallinfo();
00051         return info.ordblks;
00052     }
00053 
00055     return_type used() const
00056     {
00057         struct mallinfo info = mallinfo();
00058         return info.uordblks;
00059     }
00060 
00062     return_type not_used() const
00063     {
00064         struct mallinfo info = mallinfo();
00065         return info.fordblks;
00066     }
00067 
00069     return_type releasable() const
00070     {
00071         struct mallinfo info = mallinfo();
00072         return info.keepcost;
00073     }
00074 
00076     return_type max_allocated() const
00077     {
00078         struct mallinfo info = mallinfo();
00079         return info.usmblks;
00080     }
00081 
00083     return_type fastbin_blocks() const
00084     {
00085         struct mallinfo info = mallinfo();
00086         return info.smblks;
00087     }
00088 
00090     return_type fastbin_free() const
00091     {
00092         struct mallinfo info = mallinfo();
00093         return info.fsmblks;
00094     }
00095 
00097     return_type from_system_mmap() const
00098     {
00099         struct mallinfo info = mallinfo();
00100         return info.hblkhd;
00101     }
00102 
00104     return_type mmap_chunks() const
00105     {
00106         struct mallinfo info = mallinfo();
00107         return info.hblks;
00108     }
00109 
00111     return_type from_system_total() const
00112     {
00113         return from_system_nmmap() + from_system_mmap();
00114     }
00115 #endif
00116 };
00117 
00119 inline std::ostream & operator << (std::ostream & s, const malloc_stats & st)
00120 {
00121 #if !defined(__APPLE__) && !defined(__FreeBSD__)
00122     s << "MALLOC statistics" << std::endl;
00123     s << "=================================================================" << std::endl;
00124     s << "Space allocated from system not using mmap: " << st.from_system_nmmap() << " bytes" << std::endl;
00125     s << "       number of free chunks                       : " << st.free_chunks() << std::endl;
00126     s << "       space allocated and in use                  : " << st.used() << " bytes" << std::endl;
00127     s << "       space allocated but not in use              : " << st.not_used() << " bytes" << std::endl;
00128     s << "       top-most, releasable (via malloc_trim) space: " << st.releasable() << " bytes" << std::endl;
00129     s << "       maximum total allocated space (?)           : " << st.max_allocated() << " bytes" << std::endl;
00130     s << "   FASTBIN blocks " << std::endl;
00131     s << "       number of fastbin blocks: " << st.fastbin_blocks() << std::endl;
00132     s << "       space available in freed fastbin blocks: " << st.fastbin_free() << " bytes" << std::endl;
00133     s << "Space allocated from system using mmap: " << st.from_system_mmap() << " bytes" << std::endl;
00134     s << "       number of chunks allocated via mmap(): " << st.mmap_chunks() << std::endl;
00135     s << "Total space allocated from system (mmap and not mmap): " <<
00136     st.from_system_total() << " bytes" << std::endl;
00137     s << "=================================================================" << std::endl;
00138 #else
00139     s << "MALLOC statistics are not supported on this platform";
00140     STXXL_UNUSED(st);
00141 #endif
00142     return s;
00143 }
00144 
00145 class malloc_setup
00146 { };
00147 
00148 __STXXL_END_NAMESPACE
00149 
00150 #endif // !STXXL_MALLOC_H

Generated by  doxygen 1.7.1