source: git/Singular/mmheap.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: 3.9 KB
Line 
1#ifndef MEMHEAP_H
2#define MEMHEAP_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id: mmheap.h,v 1.4 1998-12-16 18:43:41 Singular Exp $ */
7#include <stdlib.h>
8#include "structs.h"
9#include "mmpage.h"
10
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15/*****************************************************************
16 *
17 * Declaration and Configuration
18 *
19 *****************************************************************/
20struct sip_memHeap
21{
22  void* current;
23  void* pages;
24  size_t size;
25};
26
27/*****************************************************************
28 *
29 * Basic routines
30 *
31 *****************************************************************/
32
33/* Initializes Heap, assumes size < SIZE_OF_HEAP_PAGE */
34extern void mmInitHeap(memHeap heap, size_t size);
35/* UNCONDITIONALLY frees all pages of heap */
36extern void mmClearHeap(memHeap heap);
37/* Tries to free as many unused pages of heap as possible */
38extern void mmCleanHeap(memHeap heap);
39/* creates and initializes heap */
40extern memHeap mmCreateHeap(size_t size);
41/* Clears and destroys heap */
42void mmDestroyHeap(memHeap *heap);
43/* Merges what is free in Heap "what" into free list of heap "into" */
44void mmMergeHeap(memHeap into, memHeap what);
45
46#define MM_HEAP_ADDR_UNKNOWN_FLAG 0
47#define MM_HEAP_ADDR_USED_FLAG   1
48#define MM_HEAP_ADDR_FREE_FLAG   2
49
50#ifndef HEAP_DEBUG
51
52#define mmAllocHeap               _mmAllocHeap
53#define mmFreeHeap                _mmFreeHeap
54
55#define mmCheckHeap(heap)           1
56#define mmCheckHeapAddr(addr, heap) 1
57
58#else
59
60/* use this variables to control level of HEAP_DEBUG at run-time
61   (see mod2.h for details) */
62extern int mm_HEAP_DEBUG;
63
64#define mmAllocHeap(res, heap)\
65  ((void*)(res)) = mmDebugAllocHeap(heap, __FILE__, __LINE__)
66void * mmDebugAllocHeap(memHeap heap, const char*, int );
67
68#define mmFreeHeap(addr, heap)\
69  mmDebugFreeHeap(addr, heap, __FILE__, __LINE__)
70void   mmDebugFreeHeap(void* addr, memHeap heap, const char*, int );
71
72#define mmCheckHeap(heap)\
73  mmDebugCheckHeap(heap, __FILE__, __LINE__)
74int mmDebugCheckHeap(memHeap heap, const char* fn, int line);
75
76#define mmCheckHeapAddr(addr, heap) \
77  mmDebugCheckHeapAdr(addr, heap, MM_HEAP_ADDR_USED_FLAG, __FILE__, __LINE__)
78int mmDebugCheckHeapAddr(void* addr, memHeap heap, int flag,
79                         const char* fn, int l);
80
81#endif
82
83/*****************************************************************
84 *
85 * Low-level allocation routines
86 *
87 *****************************************************************/
88
89/* Allocates memory block from a heap */
90#define _mmAllocHeap(what, heap)                            \
91do                                                          \
92{                                                           \
93  if ((heap)->current == NULL) mmAllocNewHeapPage(heap);    \
94  ((void*) (what)) = (heap)->current;                       \
95  (heap)->current =  *((void**)(heap)->current);            \
96}                                                           \
97while (0)
98
99/* Frees addr into heap, assumes  addr was previously allocated from heap */
100#define _mmFreeHeap(addr, heap)                  \
101do                                              \
102{                                               \
103  *((void**) addr) = (heap)->current;           \
104  (heap)->current = (void*) addr;               \
105}                                               \
106while (0)
107
108/*****************************************************************
109 *
110 * Auxillary routines
111 *
112 *****************************************************************/
113void mmAllocNewHeapPage(memHeap heap);
114
115#if 0
116#define mmGetNumberOfAllocatedHeapPages(heap) ((heap)->pnumber)
117#define mmGetNumberOfAllocatedHeapMemory(heap) ((heap)->pnumber * SIZE_OF_PAGE)
118#endif
119#define mmGetHeapBlockSize(heap) ((heap)->size)
120
121#define SIZE_OF_HEAP_PAGE (SIZE_OF_PAGE - SIZEOF_VOIDP)
122#define SIZE_OF_HEAP_PAGE_HEADER (SIZEOF_VOIDP)
123
124#ifdef __cplusplus
125}
126#endif
127
128#endif /* MEMHEAP_H */
129
Note: See TracBrowser for help on using the repository browser.