source: git/Singular/mmemory.h @ e48debd

fieker-DuValspielwiese
Last change on this file since e48debd was e48debd, checked in by Hans Schönemann <hannes@…>, 25 years ago
*hannes: no .h file should include mod2.h git-svn-id: file:///usr/local/Singular/svn/trunk@2766 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 13.1 KB
Line 
1#ifndef MMEMORY_H
2#define MMEMORY_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id: mmemory.h,v 1.13 1998-12-16 18:43:40 Singular Exp $ */
7/*
8* ABSTRACT
9*/
10#include <stdlib.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16#include "structs.h"
17#include "mmheap.h"
18
19/**********************************************************************
20 *
21 * Memory allocation
22 *
23 **********************************************************************/
24
25#ifndef MDEBUG
26
27void * mmAllocBlock( size_t );
28void * mmAllocBlock0( size_t );
29void   mmFreeBlock( void*, size_t );
30void * mmReallocBlock( void*, size_t, size_t );
31void * mmReallocBlock0( void*, size_t, size_t );
32void * mmAlloc( size_t );
33void * mmRealloc( void*, size_t );
34void   mmFree( void* );
35char * mmStrdup( const char* );
36
37#define AllocHeap               mmAllocHeap
38#define FreeHeap                mmFreeHeap
39#define Alloc                   mmAllocBlock
40#define Alloc0                  mmAllocBlock0
41#define Free                    mmFreeBlock
42#define ReAlloc                 mmReallocBlock
43#define ReAlloc0                mmReallocBlock0
44#define FreeL                   mmFree
45#define AllocL                  mmAlloc
46#define mstrdup                 mmStrdup
47
48
49#else /* MDEBUG */
50
51void * mmDBAllocHeap(memHeap heap, char*, int );
52void   mmDBFreeHeap(void* addr, memHeap heap, char*, int );
53void * mmDBAllocBlock( size_t, char*, int );
54void * mmDBAllocBlock0( size_t,  char*, int);
55void   mmDBFreeBlock( void*, size_t, char*, int);
56void * mmDBReallocBlock( void*, size_t, size_t, char*, int );
57void * mmDBReallocBlock0( void*, size_t, size_t, char*, int );
58void * mmDBAlloc( size_t, char*, int );
59void * mmDBRealloc( void*, size_t, char*, int );
60void   mmDBFree( void*, char*, int );
61char * mmDBStrdup( const char * s, char *fname, int lineno);
62
63#define AllocHeap(res, heap)\
64  ((void*)(res)) = mmDBAllocHeap(heap, __FILE__, __LINE__)
65#define FreeHeap(addr, heap)\
66  mmDBFreeHeap(addr, heap,  __FILE__, __LINE__)
67#define Alloc(s)                mmDBAllocBlock(s, __FILE__, __LINE__)
68#define Alloc0(s)               mmDBAllocBlock0(s, __FILE__, __LINE__)
69#define Free(a,s)               mmDBFreeBlock(a, s, __FILE__, __LINE__)
70#define ReAlloc(a,o,n)          mmDBReallocBlock(a, o, n, __FILE__, __LINE__)
71#define ReAlloc0(a,o,n)         mmDBReallocBlock0(a, o, n, __FILE__, __LINE__)
72#define AllocL(s)               mmDBAlloc(s, __FILE__, __LINE__)
73#define FreeL(a)                mmDBFree(a,__FILE__,__LINE__)
74#define mstrdup(s)              mmDBStrdup(s, __FILE__, __LINE__)
75
76#endif /* MDEBUG */
77
78
79/**********************************************************************
80 *
81 * Tests of memory (for MDEBUG, only)
82 *
83 **********************************************************************/
84
85#ifdef MDEBUG
86
87/* use this variables to control level of MDEBUG at run-time
88   (see mod2.h for details) */
89extern int mm_MDEBUG;
90
91BOOLEAN mmDBTestHeapBlock(const void* adr, const memHeap heap,
92                          const char * fname, const int lineno );
93BOOLEAN mmDBTestBlock(const void* adr, const size_t size,
94                      const char * fname, const int lineno );
95BOOLEAN mmDBTest(const void* adr, const char * fname, const int lineno);
96
97#define mmTestHeap(a, h)\
98  mmDBTestHeapBlock(a, h, __FILE__, __LINE__)
99#define mmTest(A,B)     mmDBTestBlock(A,B,__FILE__,__LINE__)
100#define mmTestL(A)      mmDBTest(A,__FILE__,__LINE__)
101#define mmTestP(A,B)    mmDBTestBlock(A,B,__FILE__,__LINE__)
102#define mmTestLP(A)     mmDBTest(A,__FILE__,__LINE__)
103
104int mmTestMemory();
105int mmTestHeaps();
106
107void mmPrintUsedList();
108
109#else
110
111
112#define mmTestHeap(addr, heap) mmCheckHeapAddr(addr, heap)
113#define mmTest(A,B) TRUE
114#define mmTestL(A)  TRUE
115#define mmTestP(A,B)
116#define mmTestLP(A)
117#define mmTestMemory 1
118#define mmTestHeaps 1
119
120#endif /* MDEBUG */
121
122
123/**********************************************************************
124 *
125 * Misc stuff
126 *
127 **********************************************************************/
128
129/* For handling of monomials */
130size_t mmSpecializeBlock( size_t );
131size_t mmGetSpecSize();
132extern memHeap mm_specHeap;
133
134/* for handling of memory statistics */
135int mmMemAlloc( void );
136int mmMemUsed( void );
137#ifdef HAVE_SBRK
138int mmMemPhysical( void );
139#endif
140void mmPrintStat();
141
142size_t mmSizeL( void* );
143
144/**********************************************************************
145 *
146 * Some operations on linked lists of memory
147 *
148 **********************************************************************/
149/* The following routines assume that Next(list) == *((void**) list) */
150
151/* Returns the length of a memory list; assumes list has no cycles */
152int mmListLength(void* list);
153/* Returns last non-NULL element of list; assumes list has no cycles */
154void* mmListLast(void* list);
155/* returns 1, if addr is contained in memory list
156 * 0, otherwise */
157int mmIsAddrOnList(void* addr, void* list);
158/* Checks whether memory list has cycles: If yes, returns address of
159 * first element of list which is contained at least twice in memory
160 * list. If no, NULL is returned */
161void* mmListHasCycle(void* list);
162
163/* The following routines assume that Next(list) == *((void**) list + next) */
164
165/* Returns the length of a memory list; assumes list has no cycles */
166int mmGListLength(void* list, int next);
167/* Returns last non-NULL element of list; assumes list has no cycles */
168void* mmGListLast(void* list, int next);
169/* returns 1, if addr is contained in memory list
170 * 0, otherwise */
171int mmIsAddrOnGList(void* addr, void* list, int next);
172/* Checks whether memory list has cycles: If yes, returns address of
173 * first element of list which is contained at least twice in memory
174 * list. If no, NULL is returned */
175void* mmGListHasCycle(void* list, int next);
176
177/**********************************************************************
178 *
179 * some fast macros for basic memory operations
180 *
181 **********************************************************************/
182#ifdef DO_DEEP_PROFILE
183extern void _memcpyW(void* p1, void* p2, long l);
184#define memcpy_nwEVEN(p1, p2, l)    _memcpyW((void*) p1, (void*) p2, (long) l)
185#define memcpy_nwODD(p1, p2, l)     _memcpyW((void*) p1, (void*) p2, (long) l)
186#define memcpyW(p1, p2, l)          _memcpyW((void*) p1, (void*) p2, (long) l)
187
188extern void _memaddW(void* p1, void* p2, void* p3, long l);
189#define memaddW(p1, p2, p3, l)          _memaddW(p1, p2, p3, l)
190#define memadd_nwODD(p1, p2, p3, l)     _memaddW(p1, p2, p3, l)
191#define memadd_nwEVEN(p1, p2, p3, l)    _memaddW(p1, p2, p3, l)
192#define memadd_nwONE(p1, p2, p3)        _memaddW(p1, p2, p3, 1)
193#define memadd_nwTWO(p1, p2, p3)        _memaddW(p1, p2, p3, 2)
194
195extern void _memsetW(void* p1, long w, long l);
196#define memsetW(p1, w, l) _memsetW(p1, w, l)
197
198#else /* ! DO_DEEP_PROFILE */
199
200#define memcpyW(p1, p2, l)                      \
201do                                              \
202{                                               \
203  long _i = l;                                  \
204  long* _s1 = (long*) p1;                       \
205  const long* _s2 = (long*) p2;                 \
206                                                \
207  for (;;)                                      \
208  {                                             \
209    *_s1 = *_s2;                                \
210    _i--;                                       \
211    if (_i == 0) break;                         \
212    _s1++;                                      \
213    _s2++;                                      \
214  }                                             \
215}                                               \
216while(0)
217
218#define memcpy_nwODD(p1, p2, l)                 \
219do                                              \
220{                                               \
221  long _i = l - 1;                              \
222  long* _s1 = (long*) p1;                       \
223  const long* _s2 = (long*) p2;                 \
224                                                \
225  *_s1++ = *_s2++;                              \
226  for (;;)                                      \
227  {                                             \
228    *_s1++ = *_s2++;                            \
229    *_s1++ = *_s2++;                            \
230    _i -= 2;                                    \
231    if (_i == 0) break;                         \
232  }                                             \
233}                                               \
234while(0)
235
236#define memcpy_nwEVEN(p1, p2, l)                \
237do                                              \
238{                                               \
239  long _i = l;                                  \
240  long* _s1 = (long*) p1;                       \
241  const long* _s2 = (long*) p2;                 \
242                                                \
243  for (;;)                                      \
244  {                                             \
245    *_s1++ = *_s2++;                            \
246    *_s1++ = *_s2++;                            \
247    _i -= 2;                                    \
248    if (_i == 0) break;                         \
249  }                                             \
250}                                               \
251while(0)
252
253#define memaddW(P1, P2, P3, L)                  \
254do                                              \
255{                                               \
256  unsigned long* _p1 = P1;                      \
257  const unsigned long* _p2 = P2;                \
258  const unsigned long* _p3 = P3;                \
259  unsigned long l = L;                          \
260                                                \
261  do                                            \
262  {                                             \
263    *_p1++ = *_p2++ + *_p3++;                   \
264    l--;                                        \
265  }                                             \
266  while(l);                                     \
267}                                               \
268while(0)
269
270#define memadd_nwODD(P1, P2, P3, L)             \
271do                                              \
272{                                               \
273  unsigned long* _p1 = P1;                      \
274  const unsigned long* _p2 = P2;                \
275  const unsigned long* _p3 = P3;                \
276  unsigned long l = L;                          \
277                                                \
278 *_p1++ = *_p2++ + *_p3++;                      \
279  l--;                                          \
280                                                \
281  do                                            \
282  {                                             \
283     *_p1++ = *_p2++ + *_p3++;                  \
284     *_p1++ = *_p2++ + *_p3++;                  \
285     l -=2;                                     \
286  }                                             \
287  while(l);                                     \
288}                                               \
289while(0)
290
291#define memadd_nwEVEN(P1, P2, P3, L)            \
292do                                              \
293{                                               \
294  unsigned long* _p1 = P1;                      \
295  const unsigned long* _p2 = P2;                \
296  const unsigned long* _p3 = P3;                \
297  unsigned long l = L;                          \
298                                                \
299  do                                            \
300  {                                             \
301     *_p1++ = *_p2++ + *_p3++;                  \
302     *_p1++ = *_p2++ + *_p3++;                  \
303     l -=2;                                     \
304  }                                             \
305  while(l);                                     \
306}                                               \
307while(0)
308
309#define memadd_nwONE(P1, P2, P3)                \
310do                                              \
311{                                               \
312  unsigned long* _p1 = P1;                      \
313  const unsigned long* _p2 = P2;                \
314  const unsigned long* _p3 = P3;                \
315                                                \
316 *_p1 = *_p2 + *_p3;                            \
317}                                               \
318while(0)
319
320#define memadd_nwTWO(P1, P2, P3)                \
321do                                              \
322{                                               \
323  unsigned long* _p1 = P1;                      \
324  const unsigned long* _p2 = P2;                \
325  const unsigned long* _p3 = P3;                \
326                                                \
327 *_p1++ = *_p2++ + *_p3++;                      \
328 *_p1 = *_p2 + *_p3;                            \
329}                                               \
330while(0)
331
332#define memsetW(P1, W, L)                       \
333do                                              \
334{                                               \
335  long* _p1 = P1;                               \
336  unsigned long _l = L;                         \
337  long _w = W;                                  \
338                                                \
339  while(_l)                                     \
340  {                                             \
341    *_p1++ = W;                                 \
342    _l--;                                       \
343  }                                             \
344}                                               \
345while(0)
346
347#endif /* DO_DEEP_PROFILE */
348
349#ifdef __cplusplus
350}
351#endif
352
353
354#endif
Note: See TracBrowser for help on using the repository browser.