source: git/omalloc/omDefaultConfig.h

spielwiese
Last change on this file was 4bde6b, checked in by Hans Schoenemann <hannes@…>, 4 years ago
spelling p1
  • Property mode set to 100644
File size: 9.6 KB
Line 
1/*******************************************************************
2 *  File:    omDefaultConfig.h
3 *  Purpose: default declaration of of configurable stuff
4 *  Author:  obachman (Olaf Bachmann)
5 *  Created: 11/99
6 *******************************************************************/
7
8/********************************************************************
9  If you want to make changes to any of these defines, create a file,
10  say, MyOmConfig.h, define your particular stuff there, and run configure with
11  --external-config-h=MyOmConfig.h.
12
13  If you also need to implement something, then implement it in, say,
14  MyOmConfig.c, and run configure with
15  --external-config-h=MyOmConfig.h --external-config-c=MyOmConfig.c
16
17  For omTest to link, you need to make sure that your implementation can also be
18  used when not linked with your application. I.e. you should also provide a
19  stand-alone implementation if OM_STANDALONE is defined.
20
21  Notice that some of these parameters can also be set at run-time, using
22  the global om_Opts struct.
23********************************************************************/
24#include <limits.h>
25#include "omConfig.h"
26/* if external config was provided, 'make' makes links from it to omExternalConfig.h */
27#ifdef OM_HAVE_EXTERNAL_CONFIG_H
28#include "omExternalConfig.h"
29#endif
30
31/* If this is larger than the track parameter given to the omDebug routines,
32   then this is used as TrackLevel: om_Opts.MinTrack is initalized with this */
33#ifndef OM_DEFAULT_MIN_TRACK
34#define OM_DEFAULT_MIN_TRACK 0
35#endif
36
37/* If this is larger than the check parameter given to the omDebug routines,
38   then this is used as CheckLevel: om_Opts.MinCheck is initalized with this */
39#ifndef OM_DEFAULT_MIN_CHECK
40#define OM_DEFAULT_MIN_CHECK 0
41#endif
42
43/* MAX options. If Max < Min, then Max value is used. */
44/* If this is smaller than the track parameter given to the omDebug routines,
45   then this is used as TrackLevel: om_Opts.MaxTrack is initalized with this */
46#ifndef OM_DEFAULT_MAX_TRACK
47#define OM_DEFAULT_MAX_TRACK 5
48#endif
49
50/* If this is smaller than the check parameter given to the omDebug routines,
51   then this is used as CheckLevel: om_Opts.MaxCheck is initalized with this */
52#ifndef OM_DEFAULT_MAX_CHECK
53#define OM_DEFAULT_MAX_CHECK 10
54#endif
55
56/* If this is greater than 0, then the omDebugFree omDebugRealloc delay freeing memory
57   by that many blocks: Initalizes omOpts.Keep
58   Setting this to LONG_MAX never frees memory */
59#ifndef OM_DEFAULT_KEEP
60#define OM_DEFAULT_KEEP 100
61#endif
62
63/* If this is set to
64   0: errors are not reported, only the global variable om_ErrorStatus is set
65   1: short error description, i.e. omError2String(om_ErrorStatus), is reported to stderr
66   2: backtrace of current stack is printed to stderr
67   3: more detailed error description is printed -- this might not make too much sense if
68      you are not familiar with omalloc
69   Initializes om_Opts.HowToReprotErrors
70*/
71#ifndef OM_DEFAULT_HOW_TO_REPORT_ERRORS
72#if defined(OM_INTERNAL_DEBUG)
73#define OM_DEFAULT_HOW_TO_REPORT_ERRORS 3
74#else
75#define OM_DEFAULT_HOW_TO_REPORT_ERRORS 2
76#endif
77#endif
78
79/* if this is set, then all memory allocated with track >= 1 is marked as
80   static, i.e. it is not mention in omPrintUsedAddrs */
81#ifndef OM_DEFAULT_MARK_AS_STATIC
82#define OM_DEFAULT_MARK_AS_STATIC 0
83#endif
84
85/* Number of pages per region, i.e., how many pages are allocated at once, after we
86   run out of pages: Initalizes om_Opts.PagesPerRegion
87   The higher this value is, the fewer calls to valloc (resp. mmap) need to be make,
88   but the more unused memory the application might have allocated from the operating system
89*/
90#ifndef OM_DEFAULT_PAGES_PER_REGION
91#define OM_DEFAULT_PAGES_PER_REGION 512
92#endif
93
94/* This is called if nothing goes any more, i.e., if
95   memory request can not be serviced. If set, this function should never return.*/
96#ifndef OM_DEFAULT_OUT_OF_MEMORY_FUNC
97/* This initializes om_Opts.OutOfMemoryFunc which is declared as
98   void (*OutOfMemoryFunc)(); */
99#define OM_DEFAULT_OUT_OF_MEMORY_FUNC NULL
100#endif
101#ifndef OM_OUT_OF_MEMORY_HOOK
102#define OM_OUT_OF_MEMORY_HOOK()                             \
103do                                                          \
104{                                                           \
105  if (om_Opts.OutOfMemoryFunc != NULL)                      \
106    om_Opts.OutOfMemoryFunc();                              \
107   fprintf(stderr, "***Emergency Exit: Out of Memory\n");   \
108   exit(1);                                                 \
109}                                                           \
110while (0)
111#endif
112
113/* This is called whenever no more memory could be obtained from the system.
114   It should trigger the release of as much memory by the application as possible */
115#ifndef OM_DEFAULT_MEMORY_LOW_FUNC
116/* This initializes om_Opts.MemoryLowFunc which is declared as
117   void (*MemoryLowFunc)(); */
118#define OM_DEFAULT_MEMORY_LOW_FUNC NULL
119#endif
120#ifndef OM_DEFAULT_MEMORY_LOW_HOOK
121#define OM_MEMORY_LOW_HOOK()                    \
122do                                              \
123{                                               \
124  if (om_Opts.MemoryLowFunc != NULL)            \
125    om_Opts.MemoryLowFunc();                    \
126}                                               \
127while(0)
128#endif
129
130/* This is called after an omError was reported.
131   It is especially useful to set a debugger breakpoint
132   to this func */
133#ifndef OM_DEFAULT_ERROR_HOOK
134#define OM_DEFAULT_ERROR_HOOK omErrorBreak
135#endif
136
137/*******************************************************************
138 *  File:    omSingularConfig.h
139 *  Purpose: declaration of External Config stuff for omalloc
140 *           This file is part of omDefaultConfig.h, i.e., at the the time
141 *           the omalloc library is built. Any changes to the default config
142 *           of omalloc should be done here (and, of course, you need to
143 *           rebuilt the library).
144 *  Author:  obachman@mathematik.uni-kl.de (Olaf Bachmann)
145 *  Created: 8/00
146 *******************************************************************/
147#ifdef __cplusplus
148extern "C"
149{
150#endif
151
152#include <stdlib.h>
153#include <stdio.h>
154
155
156#ifdef OM_ALLOC_SYSTEM_C
157int om_sing_opt_show_mem = 0;
158size_t om_sing_last_reported_size = 0;
159#else
160extern int om_sing_opt_show_mem;
161extern size_t om_sing_last_reported_size;
162#endif
163
164/* number of bytes for difference to report: every 1 MByte */
165#define SING_REPORT_THRESHOLD 1000*1024
166#define OM_SINGULAR_HOOK                                                        \
167do                                                                            \
168{                                                                             \
169  if (om_sing_opt_show_mem)                                                   \
170  {                                                                           \
171    size_t _current_bytes = om_Info.CurrentBytesFromMalloc +                  \
172                            (om_Info.UsedPages << LOG_BIT_SIZEOF_SYSTEM_PAGE);\
173    size_t _diff = (_current_bytes > om_sing_last_reported_size ?             \
174                   _current_bytes - om_sing_last_reported_size :              \
175                   om_sing_last_reported_size - _current_bytes);              \
176    if (_diff >= SING_REPORT_THRESHOLD)                                       \
177    {                                                                         \
178      fprintf(stdout, "[%ldk]", (long)(_current_bytes + 1023)/1024);                \
179      fflush(stdout);                                                         \
180      om_sing_last_reported_size = _current_bytes;                            \
181    }                                                                         \
182  }                                                                           \
183}                                                                             \
184while (0)
185
186#ifdef __cplusplus
187}
188#endif
189
190/********************************************************************
191 *
192 * The following can NOT be set at run time
193 *
194 ********************************************************************/
195/* The following hooks are called after the respective
196   system routine was called, and the Stats struct was updated
197   Not settable at run-time (makes no sense for these to be functions, for they would
198   be called each time the underlying malloc/valloc is called !) */
199#ifndef OM_REALLOC_HOOK
200#define OM_REALLOC_HOOK(oldsize, newsize) do {} while (0)
201#endif
202#ifndef OM_VALLOC_HOOK
203#define OM_VALLOC_HOOK(size) do {} while (0)
204#endif
205#ifndef OM_VFREE_HOOK
206#define OM_VFREE_HOOK(size) do {} while (0)
207#endif
208#define OM_MALLOC_HOOK(size)                OM_SINGULAR_HOOK
209#define OM_FREE_HOOK(size)                  OM_SINGULAR_HOOK
210#define OM_ALLOC_BINPAGE_HOOK               OM_SINGULAR_HOOK
211#define OM_FREE_BINPAGE_HOOK                OM_SINGULAR_HOOK
212
213/*
214 * Some stuff related to tracking of addresses
215 */
216
217/* minimal number of WORDS for padding before addr: needs to > 0: only relevant for track >= 3 */
218#ifndef OM_MIN_SIZEWOF_FRONT_PATTERN
219#define OM_MIN_SIZEWOF_FRONT_PATTERN 1
220#endif
221
222/* minimal number of WORDS for padding before addr: needs to > 0: only relevant for track >= 3 */
223#ifndef OM_MIN_SIZEWOF_BACK_PATTERN
224#define OM_MIN_SIZEWOF_BACK_PATTERN 1
225#endif
226
227/* maximal number of stack frames kept for stack at the allocation time of addr (track >= 2)
228   and free time of addr (track >= 5) */
229#ifndef OM_MAX_KEPT_FRAMES
230#define OM_MAX_KEPT_FRAMES 10
231#endif
232
233/* pattern with which memory is initialized, for front and back padding,
234   and for free memory: only relevant if track >= 3*/
235#ifndef OM_INIT_PATTERN
236#define OM_INIT_PATTERN    0xfe
237#endif
238#ifndef OM_FRONT_PATTERN
239#define OM_FRONT_PATTERN   0xfd
240#endif
241#ifndef OM_BACK_PATTERN
242#define OM_BACK_PATTERN    0xfc
243#endif
244#ifndef OM_FREE_PATTERN
245#define OM_FREE_PATTERN    0xfb
246#endif
Note: See TracBrowser for help on using the repository browser.