Stxxl  1.2.1
malloc.h
1 /***************************************************************************
2  * include/stxxl/bits/utils/malloc.h
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2003 Roman Dementiev <dementiev@mpi-sb.mpg.de>
7  *
8  * Distributed under the Boost Software License, Version 1.0.
9  * (See accompanying file LICENSE_1_0.txt or copy at
10  * http://www.boost.org/LICENSE_1_0.txt)
11  **************************************************************************/
12 
13 #ifndef STXXL_MALLOC_H
14 #define STXXL_MALLOC_H
15 
16 #include <ostream>
17 #include <malloc.h>
18 #include <cstdlib>
19 
20 #include <stxxl/bits/namespace.h>
21 
22 
23 __STXXL_BEGIN_NAMESPACE
24 
25 
27 
30 {
31 public:
32  typedef int return_type;
33 
35  return_type from_system_nmmap() const
36  {
37  struct mallinfo info = mallinfo();
38  return info.arena;
39  }
40 
42  return_type free_chunks() const
43  {
44  struct mallinfo info = mallinfo();
45  return info.ordblks;
46  }
47 
49  return_type used() const
50  {
51  struct mallinfo info = mallinfo();
52  return info.uordblks;
53  }
54 
56  return_type not_used() const
57  {
58  struct mallinfo info = mallinfo();
59  return info.fordblks;
60  }
61 
63  return_type releasable() const
64  {
65  struct mallinfo info = mallinfo();
66  return info.keepcost;
67  }
68 
70  return_type max_allocated() const
71  {
72  struct mallinfo info = mallinfo();
73  return info.usmblks;
74  }
75 
77  return_type fastbin_blocks() const
78  {
79  struct mallinfo info = mallinfo();
80  return info.smblks;
81  }
82 
84  return_type fastbin_free() const
85  {
86  struct mallinfo info = mallinfo();
87  return info.fsmblks;
88  }
89 
91  return_type from_system_mmap() const
92  {
93  struct mallinfo info = mallinfo();
94  return info.hblkhd;
95  }
96 
98  return_type mmap_chunks() const
99  {
100  struct mallinfo info = mallinfo();
101  return info.hblks;
102  }
103 
105  return_type from_system_total() const
106  {
107  return from_system_nmmap() + from_system_mmap();
108  }
109 };
110 
112 inline std::ostream & operator << (std::ostream & s, const malloc_stats & st)
113 {
114  s << "MALLOC statistics" << std::endl;
115  s << "=================================================================" << std::endl;
116  s << "Space allocated from system not using mmap: " << st.from_system_nmmap() << " bytes" << std::endl;
117  s << " number of free chunks : " << st.free_chunks() << std::endl;
118  s << " space allocated and in use : " << st.used() << " bytes" << std::endl;
119  s << " space allocated but not in use : " << st.not_used() << " bytes" << std::endl;
120  s << " top-most, releasable (via malloc_trim) space: " << st.releasable() << " bytes" << std::endl;
121  s << " maximum total allocated space (?) : " << st.max_allocated() << " bytes" << std::endl;
122  s << " FASTBIN blocks " << std::endl;
123  s << " number of fastbin blocks: " << st.fastbin_blocks() << std::endl;
124  s << " space available in freed fastbin blocks: " << st.fastbin_free() << " bytes" << std::endl;
125  s << "Space allocated from system using mmap: " << st.from_system_mmap() << " bytes" << std::endl;
126  s << " number of chunks allocated via mmap(): " << st.mmap_chunks() << std::endl;
127  s << "Total space allocated from system (mmap and not mmap): " <<
128  st.from_system_total() << " bytes" << std::endl;
129  s << "=================================================================" << std::endl;
130  return s;
131 }
132 
133 class malloc_setup
134 { };
135 
136 __STXXL_END_NAMESPACE
137 
138 #endif // !STXXL_MALLOC_H