This section lists the Insure++ functions that you can call programmatically.
If you are inserting these routines into your source code, you might want to use the pre-processor symbol __INSURE__ so that they will only be called when compiling with the appropriate tools. For example:
void grind_away() {
#ifdef __INSURE__
_Insure_checking_enable(0);
//disables Insure++ checking
#endif
... code ...
#ifdef __INSURE__
_Insure_checking_enable(1);
//enables Insure++ checking
#endif
} |
In this way, you can use the same source code when compiling with or without Insure++. You will also need to add prototypes for these functions to your code, particularly if you are calling these C functions from C++ code. Make sure that in this case your prototype is properly marked extern "C".
This routine affects the behavior of Insure++ and is normally called from within your source code.
void _Insure_printf(const char *fmt,[,arg...]);
Causes Insure++ to add the given character string to its output.
size_t _Insure_list_allocated_memory(unsigned int mode)Prints the total number of allocated blocks and the total number of bytes allocated. If mode is set to 2, Insure++ lists all allocated memory blocks and their sizes. If mode is set to 1, Insure++ lists only newly allocated or re-allocated blocks (blocks allocated or re-allocated since the last time this function was called). If mode is set to 0, Insure++ does not list any blocks; it only prints the total allocation. This function returns the total number of bytes allocated.
void _Insure_mem_info(void *ptr);Displays all information known about the memory block whose address is ptr. For example, the following code might generate the output shown next:
#include <stdlib.h>
main()
{
char *p, buf[128];
p = malloc(100);
#ifdef __INSURE__
_Insure_mem_info(buf);
_Insure_mem_info(p);
#endif
... |
Pointer : 0xf7fff74c (stack) Offset : 0 bytes In block : 0xf7fff74c thru 0xf7fff7cb (128 bytes) buf, declared at foo.c, 4 Pointer : 0x00024b98 (heap) Offset : 0 bytes In block : 0x00024b98 thru 0x00024bfb (100 bytes) p, allocated at foo.c, 6 |
void _Insure_ptr_info(void **ptr);Displays all information about the pointer whose address is passed. For example, the following code might generate the output shown next:
#include <stdlib.h>
main()
{
char *p, buf[128];
p = malloc(100);
#ifdef __INSURE__
_Insure_ptr_info(&p);
#endif
... |
Pointer : 0x00024b98 (heap) Offset : 0 bytes In block : 0x00024b98 thru 0x00024bfb (100 bytes) p, allocated at foo.c, 6 |
void _Insure_leak_summary()Prompts Insure++ to report a leak summary at various points during execution. If the leak_sweep option is enabled, this function prompts Insure++ to mark and sweep all heap blocks.
The leak_sweep option should always be enabled when using this function. If the summarize_leaks and/or summarize_outstanding options are set, this function prompts Insure++ to report a leak summary. It also notifies Inuse of all leaked heap blocks. This function may be called repeatedly throughout a process’s lifetime. This is useful for monitoring leaks in a continuously running process (for example, a server) when the leak_search option has been disabled to improve performance.
void _Insure_new_leak_summary()Prompts Insure++ to report any new leaks that have occurred since the last call to _Insure_new_leak_summary.
The leak_sweep option should always be enabled when using this function. If the summarize_leaks and/or summarize_outstanding options are set, this function prompts Insure++ to report a leak summary. It also notifies Inuse of all leaked heap blocks.
This function may be called repeatedly throughout a process’s lifetime. This is useful for monitoring leaks in a continuously running process (for example, a server) when the leak_search option has been disabled to improve performance.
You can use the _Insure_trace_annotate() and _Insure_trace_enable() APIs to trace program execution. See Tracing Program Execution for details.