• 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 #include <malloc.h>
00018 #include <cstdlib>
00019 
00020 #include <stxxl/bits/namespace.h>
00021 
00022 
00023 __STXXL_BEGIN_NAMESPACE
00024 
00025 
00027 
00029 class malloc_stats
00030 {
00031 public:
00032     typedef int return_type;
00033 
00035     return_type from_system_nmmap() const
00036     {
00037         struct mallinfo info = mallinfo();
00038         return info.arena;
00039     }
00040 
00042     return_type free_chunks() const
00043     {
00044         struct mallinfo info = mallinfo();
00045         return info.ordblks;
00046     }
00047 
00049     return_type used() const
00050     {
00051         struct mallinfo info = mallinfo();
00052         return info.uordblks;
00053     }
00054 
00056     return_type not_used() const
00057     {
00058         struct mallinfo info = mallinfo();
00059         return info.fordblks;
00060     }
00061 
00063     return_type releasable() const
00064     {
00065         struct mallinfo info = mallinfo();
00066         return info.keepcost;
00067     }
00068 
00070     return_type max_allocated() const
00071     {
00072         struct mallinfo info = mallinfo();
00073         return info.usmblks;
00074     }
00075 
00077     return_type fastbin_blocks() const
00078     {
00079         struct mallinfo info = mallinfo();
00080         return info.smblks;
00081     }
00082 
00084     return_type fastbin_free() const
00085     {
00086         struct mallinfo info = mallinfo();
00087         return info.fsmblks;
00088     }
00089 
00091     return_type from_system_mmap() const
00092     {
00093         struct mallinfo info = mallinfo();
00094         return info.hblkhd;
00095     }
00096 
00098     return_type mmap_chunks() const
00099     {
00100         struct mallinfo info = mallinfo();
00101         return info.hblks;
00102     }
00103 
00105     return_type from_system_total() const
00106     {
00107         return from_system_nmmap() + from_system_mmap();
00108     }
00109 };
00110 
00112 inline std::ostream & operator << (std::ostream & s, const malloc_stats & st)
00113 {
00114     s << "MALLOC statistics" << std::endl;
00115     s << "=================================================================" << std::endl;
00116     s << "Space allocated from system not using mmap: " << st.from_system_nmmap() << " bytes" << std::endl;
00117     s << "       number of free chunks                       : " << st.free_chunks() << std::endl;
00118     s << "       space allocated and in use                  : " << st.used() << " bytes" << std::endl;
00119     s << "       space allocated but not in use              : " << st.not_used() << " bytes" << std::endl;
00120     s << "       top-most, releasable (via malloc_trim) space: " << st.releasable() << " bytes" << std::endl;
00121     s << "       maximum total allocated space (?)           : " << st.max_allocated() << " bytes" << std::endl;
00122     s << "   FASTBIN blocks " << std::endl;
00123     s << "       number of fastbin blocks: " << st.fastbin_blocks() << std::endl;
00124     s << "       space available in freed fastbin blocks: " << st.fastbin_free() << " bytes" << std::endl;
00125     s << "Space allocated from system using mmap: " << st.from_system_mmap() << " bytes" << std::endl;
00126     s << "       number of chunks allocated via mmap(): " << st.mmap_chunks() << std::endl;
00127     s << "Total space allocated from system (mmap and not mmap): " <<
00128     st.from_system_total() << " bytes" << std::endl;
00129     s << "=================================================================" << std::endl;
00130     return s;
00131 }
00132 
00133 class malloc_setup
00134 { };
00135 
00136 __STXXL_END_NAMESPACE
00137 
00138 #endif // !STXXL_MALLOC_H

Generated by  doxygen 1.7.1