source:
git/kernel/mminit.cc
@
ab8937
Last change on this file since ab8937 was a830133, checked in by , 15 years ago | |
---|---|
|
|
File size: 1.5 KB |
Line | |
---|---|
1 | /**************************************** |
2 | * Computer Algebra System SINGULAR * |
3 | ****************************************/ |
4 | /* $Id: mminit.cc,v 1.2 2009-03-17 09:01:46 Singular Exp $ */ |
5 | /* |
6 | * ABSTRACT: init of memory management |
7 | */ |
8 | |
9 | #include <stdio.h> |
10 | #include <stdlib.h> |
11 | |
12 | #include "mod2.h" |
13 | #include "mmalloc.h" |
14 | #include "structs.h" |
15 | // this prevents the definition of malloc/free and macros |
16 | // by omalloc |
17 | #define OMALLOC_C |
18 | #include "omalloc.h" |
19 | |
20 | #include <si_gmp.h> |
21 | |
22 | int mmIsInitialized=mmInit(); |
23 | |
24 | extern "C" |
25 | { |
26 | void omSingOutOfMemoryFunc() |
27 | { |
28 | fprintf(stderr, "\nerror: no more memory\n"); |
29 | omPrintStats(stderr); |
30 | m2_end(14); |
31 | /* should never get here */ |
32 | exit(1); |
33 | } |
34 | } |
35 | |
36 | int mmInit( void ) |
37 | { |
38 | if(mmIsInitialized==0) |
39 | { |
40 | #if defined(OMALLOC_USES_MALLOC) || defined(X_OMALLOC) |
41 | /* in mmstd.c, for some architectures freeSize() unconditionally uses the *system* free() */ |
42 | /* sage ticket 5344: http://trac.sagemath.org/sage_trac/ticket/5344 */ |
43 | /* solution: correctly check OMALLOC_USES_MALLOC from omalloc.h, */ |
44 | /* do not rely on the default in Singular as libsingular may be different */ |
45 | mp_set_memory_functions(omMallocFunc,omReallocSizeFunc,omFreeSizeFunc); |
46 | #else |
47 | mp_set_memory_functions(malloc,reallocSize,freeSize); |
48 | #endif |
49 | om_Opts.OutOfMemoryFunc = omSingOutOfMemoryFunc; |
50 | #ifndef OM_NDEBUG |
51 | om_Opts.ErrorHook = dErrorBreak; |
52 | #endif |
53 | omInitInfo(); |
54 | #ifdef OM_SING_KEEP |
55 | om_Opts.Keep = OM_SING_KEEP; |
56 | #endif |
57 | } |
58 | mmIsInitialized=1; |
59 | return 1; |
60 | } |
Note: See TracBrowser
for help on using the repository browser.