STXXL  1.4-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
malloc_count.h
Go to the documentation of this file.
1 /***************************************************************************
2  * include/stxxl/bits/utils/malloc_count.h
3  *
4  * Header containing prototypes of user-callable functions to retrieve
5  * run-time information about malloc()/free() allocation. Used with
6  * malloc_count.c, a light-weight malloc()-based heap allocation counter based
7  * on overriding malloc/free/realloc() functions.
8  *
9  * See http://panthema.net/2013/malloc_count/ for a tutorial.
10  *
11  * Part of the STXXL. See http://stxxl.sourceforge.net
12  *
13  * Copyright (C) 2013-2015 Timo Bingmann <[email protected]>
14  *
15  * Distributed under the Boost Software License, Version 1.0.
16  * (See accompanying file LICENSE_1_0.txt or copy at
17  * http://www.boost.org/LICENSE_1_0.txt)
18  **************************************************************************/
19 
20 #ifndef STXXL_UTILS_MALLOC_COUNT_HEADER
21 #define STXXL_UTILS_MALLOC_COUNT_HEADER
22 
23 #include <cstdlib>
24 
25 #ifdef __cplusplus
26 extern "C" { /* for inclusion from C++ */
27 #endif
28 
29 /* returns the currently allocated amount of memory */
30 extern size_t malloc_count_current(void);
31 
32 /* returns the current peak memory allocation */
33 extern size_t malloc_count_peak(void);
34 
35 /* resets the peak memory allocation to current */
36 extern void malloc_count_reset_peak(void);
37 
38 /* typedef of callback function */
39 typedef void (* malloc_count_callback_type)(void* cookie, size_t current);
40 
41 /* supply malloc_count with a callback function that is invoked on each change
42  * of the current allocation. The callback function must not use
43  * malloc()/realloc()/free() or it will go into an endless recursive loop! */
45  void* cookie);
46 
47 /* user function which prints current and peak allocation to stderr */
48 extern void malloc_count_print_status(void);
49 
50 #ifdef __cplusplus
51 } /* extern "C" */
52 #endif
53 
54 #endif // !STXXL_UTILS_MALLOC_COUNT_HEADER
void malloc_count_reset_peak(void)
size_t malloc_count_current(void)
void malloc_count_set_callback(malloc_count_callback_type cb, void *cookie)
void malloc_count_print_status(void)
void(* malloc_count_callback_type)(void *cookie, size_t current)
Definition: malloc_count.h:39
size_t malloc_count_peak(void)