malloc_count.h
Go to the documentation of this file.
1 /******************************************************************************
2  * malloc_count.h
3  *
4  * Header containing prototypes of user-callable functions to retrieve run-time
5  * information about malloc()/free() allocation.
6  *
7  ******************************************************************************
8  * Copyright (C) 2013 Timo Bingmann <tb@panthema.net>
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a copy
11  * of this software and associated documentation files (the "Software"), to
12  * deal in the Software without restriction, including without limitation the
13  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
14  * sell copies of the Software, and to permit persons to whom the Software is
15  * furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included in
18  * all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26  * IN THE SOFTWARE.
27  *****************************************************************************/
28 
29 #pragma once
30 
31 #include <stdlib.h>
32 #include <stdbool.h>
33 #include <functional>
34 
35 namespace MallocCount
36 {
40 size_t getCurrent(void);
41 
45 size_t getPeak(void);
46 
50 void resetPeak(void);
51 
55 size_t getTotal(void);
56 
60 void resetTotal(void);
61 
65 size_t getAllocCount(void);
66 
71 void setAllocLimit(size_t maxBytes);
72 
77 using Callback = std::function<void(size_t current)>;
78 
84 void setCallback(Callback callback);
85 
89 void enableLogging(bool enable);
90 
94 void setLogThreshold(size_t threshold);
95 
96 }; // namespace MallocCount
void enable(Handler &commandHandler, HardwareSerial &serial)
Definition: malloc_count.h:36
size_t getCurrent(void)
Get the currently allocated amount of memory.
void resetPeak(void)
Reset the peak memory allocation to current.
void setLogThreshold(size_t threshold)
Set minimum allocation size for log output (when enabled)
size_t getPeak(void)
Get the peak memory allocation.
size_t getTotal(void)
Get the total cumulative memory allocation.
std::function< void(size_t current)> Callback
Callback function type.
Definition: malloc_count.h:77
void setCallback(Callback callback)
Set a callback function that is invoked on each change of the current allocation.
size_t getAllocCount(void)
Get the total number of allocations.
void enableLogging(bool enable)
Enable/disable logging.
void setAllocLimit(size_t maxBytes)
Set an allocation limit.
void resetTotal(void)
Reset the total cumulative memory allocation to zero.