http://stxxl.sourceforge.net
<dementiev@mpi-sb.mpg.de>
<beckmann@cs.uni-frankfurt.de>
http://www.boost.org/LICENSE_1_0.txt
#ifndef STXXL_MALLOC_H
#define STXXL_MALLOC_H
#include <ostream>
#ifdef __FreeBSD__
#include <stdlib.h>
#else
#include <malloc.h>
#endif
#include <cstdlib>
#include <stxxl/bits/namespace.h>
__STXXL_BEGIN_NAMESPACE
class malloc_stats
{
#if !defined(__APPLE__) && !defined(__FreeBSD__)
public:
typedef int return_type;
return_type from_system_nmmap() const
{
struct mallinfo info = mallinfo();
return info.arena;
}
return_type free_chunks() const
{
struct mallinfo info = mallinfo();
return info.ordblks;
}
return_type used() const
{
struct mallinfo info = mallinfo();
return info.uordblks;
}
return_type not_used() const
{
struct mallinfo info = mallinfo();
return info.fordblks;
}
return_type releasable() const
{
struct mallinfo info = mallinfo();
return info.keepcost;
}
return_type max_allocated() const
{
struct mallinfo info = mallinfo();
return info.usmblks;
}
return_type fastbin_blocks() const
{
struct mallinfo info = mallinfo();
return info.smblks;
}
return_type fastbin_free() const
{
struct mallinfo info = mallinfo();
return info.fsmblks;
}
return_type from_system_mmap() const
{
struct mallinfo info = mallinfo();
return info.hblkhd;
}
return_type mmap_chunks() const
{
struct mallinfo info = mallinfo();
return info.hblks;
}
return_type from_system_total() const
{
return from_system_nmmap() + from_system_mmap();
}
#endif
};
inline std::ostream & operator << (std::ostream & s, const malloc_stats & st)
{
#if !defined(__APPLE__) && !defined(__FreeBSD__)
s << "MALLOC statistics" << std::endl;
s << "=================================================================" << std::endl;
s << "Space allocated from system not using mmap: " << st.from_system_nmmap() << " bytes" << std::endl;
s << " number of free chunks : " << st.free_chunks() << std::endl;
s << " space allocated and in use : " << st.used() << " bytes" << std::endl;
s << " space allocated but not in use : " << st.not_used() << " bytes" << std::endl;
s << " top-most, releasable (via malloc_trim) space: " << st.releasable() << " bytes" << std::endl;
s << " maximum total allocated space (?) : " << st.max_allocated() << " bytes" << std::endl;
s << " FASTBIN blocks " << std::endl;
s << " number of fastbin blocks: " << st.fastbin_blocks() << std::endl;
s << " space available in freed fastbin blocks: " << st.fastbin_free() << " bytes" << std::endl;
s << "Space allocated from system using mmap: " << st.from_system_mmap() << " bytes" << std::endl;
s << " number of chunks allocated via mmap(): " << st.mmap_chunks() << std::endl;
s << "Total space allocated from system (mmap and not mmap): " <<
st.from_system_total() << " bytes" << std::endl;
s << "=================================================================" << std::endl;
#else
s << "MALLOC statistics are not supported on this platform";
STXXL_UNUSED(st);
#endif
return s;
}
class malloc_setup
{ };
__STXXL_END_NAMESPACE
#endif