--enable-memprof
. If this option is given to the configure script, then the fid_ENABLE_MEMORY_PROFILING
proprocessor symbols gets defined; the effect is that functions such as malloc()
or strdup()
get replaced by macros that call internal functions such as fid_memory_malloc() or fid_memory_strdup(). These replacement functions count the number of bytes allocated and deallocated, the number of (de-)allocations, and store the peak memory usage. The collected values can be obtained via functions fid_memory_query() or printed to some FILE
pointer via fid_memory_show_usage(). These two names refer to real functions only if fid_ENABLE_MEMORY_PROFILING
is defined, otherwise they are macros that expand to nothing.There are, however, a few issues with this kind of memory profiling:
--enable-memprof
must also define the fid_ENABLE_MEMORY_PROFILING
symbol before including libfid.h
somewhere; otherwise the program is likely to crash.malloc()
buried inside library functions are not redirected to fid_memory_malloc(), so these do not appear in the statistics collected there. Worse, trying to free()
memory returned by such a function with fid_ENABLE_MEMORY_PROFILING
enabled will lead to program termination since free()
would have been redirected to fid_memory_free() then; but since libfid has never seen the pointer to be freed before, it assumes a program error, and terminates by calling abort()
.malloc()
) cannot be account for. This overhead is, of course, an implementation detail of your platform, and cannot be estimated at all.
Despite the drawbacks sketched above, the memory profiling facilities built into libfid are advantageous if you don't want to see the memory overhead imposed by your system's libraries and heap manager, but only the amount of memory explicitly used by your program. Additionally, keeping track of allocations inside libfid is usally much more accurate than using sampling-based methods such as utilized by memtime
for short running programs.
Defines | |
#define | fid_NOTIMPLEMENTED_STDERR |
Print message to stderr , return with return value -1. | |
#define | fid_NOTIMPLEMENTED(ERR) |
Put error into fid_Error ERR , return with return value -1. | |
#define | fid_memory_query(P, C, A, F, T) |
Macro that expands to nothing. | |
#define | fid_memory_show_usage(S) |
Macro that expands to nothing. | |
Functions | |
int | fid_utils_parse_uint_32 (const char *string, fid_Uint32 *ui, fid_Error *error) |
Parse a 32 bit unsigned integer from string. | |
int | fid_utils_parse_uint_64 (const char *string, fid_Uint64 *ui, fid_Error *error) |
Parse a 64 bit unsigned integer from string. |
#define fid_NOTIMPLEMENTED_STDERR |
#define fid_NOTIMPLEMENTED | ( | ERR | ) |
Value:
fid_error_throw(ERR,"%s() [%s:%d]: not implemented yet",\ __func__,__FILE__,__LINE__);\ return -1
ERR
, return with return value -1.
#define fid_memory_query | ( | P, | |||
C, | |||||
A, | |||||
F, | |||||
T | ) |
#define fid_memory_show_usage | ( | S | ) |
int fid_utils_parse_uint_32 | ( | const char * | string, | |
fid_Uint32 * | ui, | |||
fid_Error * | error | |||
) |
Parse a 32 bit unsigned integer from string.
This function performs good error checking.
string | Textual representation of an integer. | |
ui | The parsed value as binary 32 bit value. | |
error | Error messages go here. |
Definition at line 44 of file utilities.c.
References fid_error_throw(), and fid_utils_parse_uint_64().
int fid_utils_parse_uint_64 | ( | const char * | string, | |
fid_Uint64 * | ui, | |||
fid_Error * | error | |||
) |
Parse a 64 bit unsigned integer from string.
This function performs good error checking.
string | Textual representation of an integer. | |
ui | The parsed value as binary 64 bit value. | |
error | Error messages go here. |
Definition at line 85 of file utilities.c.
References fid_error_throw().
Referenced by fid_utils_parse_uint_32().