00001 /* 00002 * libfid - Full-text Index Data structure library 00003 * Copyright (C) 2006, 2007, 2008, 2009 Robert Homann 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00018 * MA 02110-1301 USA 00019 */ 00020 00021 #ifndef LIBDEFS_H 00022 #define LIBDEFS_H 00023 /*!\addtogroup misc Miscellaneous stuff 00024 * It is possible to use a simple form of memory profiling by configuring 00025 * \em libfid with option \c --enable-memprof. If this option is given to the 00026 * configure script, then the \c fid_ENABLE_MEMORY_PROFILING proprocessor 00027 * symbols gets defined; the effect is that functions such as \c malloc() or 00028 * \c strdup() get replaced by macros that call internal functions such as 00029 * fid_memory_malloc() or fid_memory_strdup(). These replacement functions 00030 * count the number of bytes allocated and deallocated, the number of 00031 * (de-)allocations, and store the peak memory usage. The collected values can 00032 * be obtained via functions fid_memory_query() or printed to some \c FILE 00033 * pointer via fid_memory_show_usage(). These two names refer to real functions 00034 * only if \c fid_ENABLE_MEMORY_PROFILING is defined, otherwise they are macros 00035 * that expand to nothing. 00036 * 00037 * There are, however, a few issues with this kind of memory profiling: 00038 * - It is based on macros, i.e., based on source code substitution, and can be 00039 * enabled or disabled at compile-time only. It is not possible to turn on 00040 * internal profiling in a version not compiled to do profiling, and vice 00041 * versa. As a consequence, all programs that link against a version of 00042 * \em libfid configured with \c --enable-memprof \em must also define the 00043 * \c fid_ENABLE_MEMORY_PROFILING symbol \em before including \c libfid.h 00044 * somewhere; otherwise the program is likely to crash. 00045 * - It is not 100% accurate, also because the profiling is based on macros. 00046 * Invocations of \c malloc() buried inside library functions are not 00047 * redirected to fid_memory_malloc(), so these do not appear in the 00048 * statistics collected there. Worse, trying to \c free() memory returned by 00049 * such a function with \c fid_ENABLE_MEMORY_PROFILING enabled will lead to 00050 * program termination since \c free() would have been redirected to 00051 * fid_memory_free() then; but since \em libfid has never seen the pointer to 00052 * be freed before, it assumes a program error, and terminates by calling 00053 * \c abort(). 00054 * - Memory used by the heap manager implementation (the memory overhead caused 00055 * by using \c malloc()) cannot be account for. This overhead is, of course, 00056 * an implementation detail of your platform, and cannot be estimated at all. 00057 * 00058 * Despite the drawbacks sketched above, the memory profiling facilities built 00059 * into \em libfid are advantageous if you \em don't want to see the memory 00060 * overhead imposed by your system's libraries and heap manager, but only the 00061 * amount of memory explicitly used by your program. Additionally, keeping 00062 * track of allocations inside \em libfid is usally much more accurate than 00063 * using sampling-based methods such as utilized by \c memtime for short 00064 * running programs. 00065 */ 00066 /*@{*/ 00067 #include "libfidinttypes.h" 00068 #include "memory.h" 00069 00070 /*!\brief Print message to \c stderr, return with return value -1. */ 00071 #define fid_NOTIMPLEMENTED_STDERR\ 00072 fprintf(stderr,"%s() [%s:%d]: not implemented yet\n",\ 00073 __func__,__FILE__,__LINE__);\ 00074 return -1 00075 00076 /*!\brief Put error into #fid_Error \p ERR, return with return value -1. */ 00077 #define fid_NOTIMPLEMENTED(ERR)\ 00078 fid_error_throw(ERR,"%s() [%s:%d]: not implemented yet",\ 00079 __func__,__FILE__,__LINE__);\ 00080 return -1 00081 /*@}*/ 00082 00083 #endif /* !LIBDEFS_H */