Changeset f8519e in git
- Timestamp:
- Jan 26, 1999, 3:41:42 PM (25 years ago)
- Branches:
- (u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
- Children:
- b6285e707366fbd4f332d38d696bd74910bcbe9e
- Parents:
- 8e012379f6186bcc208b49f8710913df381eb5e3
- Location:
- Singular
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/mmalloc.c
r8e0123 rf8519e 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: mmalloc.c,v 1.1 0 1999-01-18 17:28:05 SingularExp $ */4 /* $Id: mmalloc.c,v 1.11 1999-01-26 14:41:38 obachman Exp $ */ 5 5 6 6 /* … … 22 22 #include "mmprivate.h" 23 23 24 #undef HAVE_ASSUME 25 #define HAVE_ASSUME 24 26 25 27 #ifndef MDEBUG … … 166 168 167 169 #else /* MDEBUG */ 168 169 /**********************************************************************170 *171 * Auxillary routines172 *173 **********************************************************************/174 static void mmMoveDBMCB ( pDBMCB from, pDBMCB to, DBMCB * what )175 {176 what->prev->next = what->next;177 if ( what->next != NULL )178 what->next->prev = what->prev;179 what->prev = to;180 what->next = to->next;181 if (to->next!=NULL)182 to->next->prev=what;183 to->next = what;184 }185 186 static void mmMoveDBMCBInto ( pDBMCB to, pDBMCB what )187 {188 if (to->next !=NULL)189 {190 what->next = to->next;191 what->next->prev = what;192 }193 to->next = what;194 what->prev = to;195 }196 197 static void mmTakeOutDBMCB ( pDBMCB from, pDBMCB what )198 {199 what->prev->next = what->next;200 if ( what->next != NULL )201 what->next->prev = what->prev;202 }203 204 void mmDBInitNewHeapPage(memHeap heap)205 {206 DBMCB* what = (DBMCB*) heap->current;207 DBMCB* prev = NULL;208 size_t size = SizeFromRealSize(heap->size);209 210 if (mm_minAddr == 0 || mm_minAddr > (void*) what)211 mm_minAddr = (void*) what;212 213 while (what != NULL)214 {215 mmFillDBMCB(what, size, heap, MM_FREEFLAG, __FILE__, __LINE__);216 mmMoveDBMCBInto(&mm_theDBfree, what);217 prev = what;218 what = *((void**) what);219 }220 221 if (mm_maxAddr == 0 || mm_maxAddr < (void*) prev)222 mm_maxAddr = (void*) prev;223 }224 170 225 171 /********************************************************************** … … 361 307 } 362 308 mm_bytesMalloc -= tmpsize; 363 mmTakeOutDBMCB( &mm_theDBused,what );309 mmTakeOutDBMCB(what ); 364 310 free( what ); 365 311 if (BVERBOSE(V_SHOW_MEM)) mmCheckPrint(); … … 458 404 #if SIZEOF_DOUBLE == SIZEOF_VOIDP + SIZEOF_VOIDP 459 405 460 #if 0461 406 #ifdef MDEBUG 462 407 void * mmDBAllocAlignedBlock( size_t size, char* f, int l) … … 470 415 { 471 416 #ifdef MDEBUG 472 unsigned long ret = (unsigned long) _mmDBAllocBlock(size + 9, f, l); 473 #else 474 unsigned long ret = (unsigned long) _mmAllocBlock(size+SIZEOF_DOUBLE+1); 417 unsigned long ret = 418 (unsigned long) mmDBAllocBlock(size + SIZEOF_DOUBLE + 1, f, l); 419 #else 420 unsigned long ret = 421 (unsigned long) mmAllocBlock(size+SIZEOF_DOUBLE+1); 475 422 #endif 476 423 unsigned char shift = (ret + 1) & (SIZEOF_DOUBLE - 1); … … 478 425 479 426 assume(ret != 0); 480 481 return (void*) ((ret + 1) & ~(SIZEOF_DOUBLE - 1)); 427 ret = ((ret + 1) & ~(SIZEOF_DOUBLE - 1)); 428 429 assume(ret % SIZEOF_DOUBLE == 0); 430 431 return (void*) ret; 482 432 } 483 433 else … … 537 487 void* good; 538 488 #ifdef MDEBUG 539 good = mmDBAlloc Block(size, f, l);540 #else 541 good = mmAlloc Block(size);489 good = mmDBAllocAllignedBlock(size, f, l); 490 #else 491 good = mmAllocAlignedBlock(size); 542 492 #endif 543 493 … … 554 504 { 555 505 int i = mmGetIndex(size); 506 507 assume((unsigned long) addr % SIZEOF_DOUBLE == 0); 556 508 557 509 if (i < 0) … … 561 513 562 514 #ifdef MDEBUG 563 _mmDBFreeBlock(adj_addr - shift, size + SIZEOF_DOUBLE + 1, f, l);564 #else 565 _mmFreeBlock(adj_addr - shift, size + SIZEOF_DOUBLE + 1);515 mmDBFreeBlock(adj_addr - shift, size + SIZEOF_DOUBLE + 1, f, l); 516 #else 517 mmFreeBlock(adj_addr - shift, size + SIZEOF_DOUBLE + 1); 566 518 #endif 567 519 } … … 575 527 } 576 528 } 577 #endif578 529 579 530 #endif /* SIZEOF_DOUBLE == SIZEOF_VOIDP + SIZEOF_VOIDP */ -
Singular/mmcheck.c
r8e0123 rf8519e 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: mmcheck.c,v 1. 2 1999-01-05 12:18:39 SingularExp $ */4 /* $Id: mmcheck.c,v 1.3 1999-01-26 14:41:38 obachman Exp $ */ 5 5 6 6 /* … … 38 38 * 39 39 **********************************************************************/ 40 41 void mmMoveDBMCB ( pDBMCB from, pDBMCB to, DBMCB * what ) 42 { 43 what->prev->next = what->next; 44 if ( what->next != NULL ) 45 what->next->prev = what->prev; 46 what->prev = to; 47 what->next = to->next; 48 if (to->next!=NULL) 49 to->next->prev=what; 50 to->next = what; 51 } 52 53 void mmMoveDBMCBInto ( pDBMCB to, pDBMCB what ) 54 { 55 if (to->next !=NULL) 56 { 57 what->next = to->next; 58 what->next->prev = what; 59 } 60 to->next = what; 61 what->prev = to; 62 } 63 64 void mmTakeOutDBMCB ( pDBMCB what ) 65 { 66 what->prev->next = what->next; 67 if ( what->next != NULL ) 68 what->next->prev = what->prev; 69 } 70 71 void mmDBSetHeapsOfBlocks(memHeap fromheap, memHeap toheap) 72 { 73 memHeapPage pages = fromheap->pages; 74 int nblocks = SIZE_OF_HEAP_PAGE / toheap->size; 75 int i; 76 77 assume(fromheap->size == toheap->size); 78 while (pages != NULL) 79 { 80 DBMCB *what = (DBMCB*) (((char*) pages) + SIZE_OF_HEAP_PAGE_HEADER); 81 82 for (i=0; i<nblocks; i++) 83 { 84 what->heap = toheap; 85 what = (DBMCB*) (((char*) what) + toheap->size); 86 } 87 pages = pages->next; 88 } 89 } 90 91 void mmDBInitNewHeapPage(memHeap heap) 92 { 93 DBMCB* what = (DBMCB*) heap->current; 94 DBMCB* prev = NULL; 95 size_t size = SizeFromRealSize(heap->size); 96 97 if (mm_minAddr == 0 || mm_minAddr > (void*) what) 98 mm_minAddr = (void*) what; 99 100 while (what != NULL) 101 { 102 mmFillDBMCB(what, size, heap, MM_FREEFLAG, __FILE__, __LINE__); 103 mmMoveDBMCBInto(&mm_theDBfree, what); 104 prev = what; 105 what = *((void**) what); 106 } 107 108 if (mm_maxAddr == 0 || mm_maxAddr < (void*) prev) 109 mm_maxAddr = (void*) prev; 110 } 40 111 41 112 static int mmPrintDBMCB ( DBMCB * what, char* msg , int given_size) -
Singular/mmemory.h
r8e0123 rf8519e 4 4 * Computer Algebra System SINGULAR * 5 5 ****************************************/ 6 /* $Id: mmemory.h,v 1.1 4 1998-12-18 11:11:38obachman Exp $ */6 /* $Id: mmemory.h,v 1.15 1999-01-26 14:41:39 obachman Exp $ */ 7 7 /* 8 8 * ABSTRACT … … 34 34 void mmFree( void* ); 35 35 char * mmStrdup( const char* ); 36 #if 0 /* Alligned Allloc does not work, yet */37 36 void * mmAllocAlignedBlock( size_t ); 38 37 void * mmAllocAlignedBlock0( size_t ); 39 void * mmFreeAlignedBlock( void*, size_t ); 40 #endif 38 void mmFreeAlignedBlock( void*, size_t ); 41 39 42 40 #define AllocHeap mmAllocHeap … … 50 48 #define AllocL mmAlloc 51 49 #define mstrdup mmStrdup 52 #if 053 50 #define AllocAligned0 mmAllocAlignedBlock0 54 51 #define AllocAligned mmAllocAlignedBlock 55 52 #define FreeAligned mmFreeAlignedBlock 56 #endif57 53 58 54 #else /* MDEBUG */ … … 69 65 void mmDBFree( void*, char*, int ); 70 66 char * mmDBStrdup( const char * s, char *fname, int lineno); 71 #if 072 67 void * mmDBAllocAlignedBlock( size_t, char*, int ); 73 68 void * mmDBAllocAlignedBlock0( size_t, char*, int); 74 void * mmDBFreeAlignedBlock( void*, size_t, char*, int ); 75 #endif 69 void mmDBFreeAlignedBlock( void*, size_t, char*, int ); 76 70 77 71 #define AllocHeap(res, heap)\ … … 87 81 #define FreeL(a) mmDBFree(a,__FILE__,__LINE__) 88 82 #define mstrdup(s) mmDBStrdup(s, __FILE__, __LINE__) 89 #if 090 83 #define AllocAligned(s) mmDBAllocAlignedBlock(s, __FILE__, __LINE__) 91 84 #define AllocAligned0(s) mmDBAllocAlignedBlock0(s, __FILE__, __LINE__) 92 85 #define FreeAligned(a,s) mmDBFreeAlignedBlock(a, s, __FILE__, __LINE__) 93 #endif94 86 95 87 #endif /* MDEBUG */ … … 167 159 **********************************************************************/ 168 160 /* The following routines assume that Next(list) == *((void**) list) */ 169 161 /* Removes element from list, if contained in it and returns list */ 162 void* mmRemoveFromList(void* list, void* element); 170 163 /* Returns the length of a memory list; assumes list has no cycles */ 171 164 int mmListLength(void* list); -
Singular/mmheap.c
r8e0123 rf8519e 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: mmheap.c,v 1. 7 1998-12-02 13:57:33obachman Exp $ */4 /* $Id: mmheap.c,v 1.8 1999-01-26 14:41:40 obachman Exp $ */ 5 5 6 6 #include "mod2.h" … … 38 38 void mmClearHeap(memHeap heap) 39 39 { 40 void* page ; 41 void* next_page; 40 memHeapPage page, next_page; 42 41 43 42 mmCheckHeap(heap); … … 47 46 while(page != NULL) 48 47 { 49 next_page = mmGetPageOfAddr(*((void**) page));50 mmFreePage( page);48 next_page = page->next; 49 mmFreePage((void*) page); 51 50 page = next_page; 52 51 } … … 57 56 void mmAllocNewHeapPage(memHeap heap) 58 57 { 59 void* newpage =mmGetPage();58 memHeapPage newpage = (memHeapPage) mmGetPage(); 60 59 int i = 1, n = SIZE_OF_HEAP_PAGE / heap->size; 61 assume(heap != NULL && heap->current == NULL); 62 assume(mmIsAddrPageAligned(newpage)); 63 64 *((void**)newpage) = heap->pages; 60 void* tmp; 61 assume(heap != NULL && newpage != NULL); 62 assume(mmIsAddrPageAligned((void*) newpage)); 63 64 newpage->next = heap->pages; 65 newpage->counter = 0; 65 66 heap->pages = newpage; 66 67 67 heap->current = (void*) (((char*)newpage) + SIZE OF_VOIDP);68 newpage= heap->current;68 heap->current = (void*) (((char*)newpage) + SIZE_OF_HEAP_PAGE_HEADER); 69 tmp = heap->current; 69 70 70 71 while (i < n) 71 72 { 72 *((void**) newpage) = (void*) (((char*)newpage) + heap->size);73 newpage = *((void**)newpage);73 *((void**)tmp) = (void*) (((char*)tmp) + heap->size); 74 tmp = *((void**)tmp); 74 75 i++; 75 76 } 76 *((void**) newpage) = NULL;77 *((void**)tmp) = NULL; 77 78 #ifdef MDEBUG 78 79 mmDBInitNewHeapPage(heap); … … 87 88 88 89 if (into == what) return; 90 #ifdef MDEBUG 91 mmDBSetHeapsOfBlocks(what, into); 92 #endif 89 93 90 94 if (what->pages != NULL) … … 108 112 } 109 113 114 #ifdef HAVE_PAGE_ALIGNMENT 115 #if 1 116 void mmRemoveHeapBlocksOfPage(memHeap heap, memHeapPage hpage) 117 { 118 void *prev = NULL, *new_current = NULL, *current = heap->current; 119 int nblocks = SIZE_OF_HEAP_PAGE / heap->size; 120 121 #ifdef HAVE_ASSUME 122 int l = mmListLength(current); 123 #endif 124 125 while (mmIsAddrOnPage(current, hpage)) 126 { 127 #ifdef MDEBUG 128 mmTakeOutDBMCB((DBMCB*) current); 129 #endif 130 if (--(nblocks) == 0) 131 { 132 new_current = *((void**) current); 133 goto Finish; 134 } 135 current = *((void**) current); 136 } 137 138 new_current = current; 139 140 while (1) 141 { 142 assume(mmListLength(new_current) == 143 l - (SIZE_OF_HEAP_PAGE / heap->size) + nblocks); 144 prev = current; 145 current = *((void**) current); 146 147 while (! mmIsAddrOnPage(current, hpage)) 148 { 149 prev = current; 150 current = *((void**) current); 151 } 152 153 #ifdef MDEBUG 154 mmTakeOutDBMCB((DBMCB*) current); 155 #endif 156 if (--(nblocks) == 0) goto Finish; 157 158 current = *((void**) current); 159 while (mmIsAddrOnPage(current, hpage)) 160 { 161 #ifdef MDEBUG 162 mmTakeOutDBMCB((DBMCB*) current); 163 #endif 164 if (--(nblocks) == 0) goto Finish; 165 current = *((void**) current); 166 } 167 *((void**) prev) = current; 168 } 169 170 Finish: 171 heap->current = new_current; 172 if (prev != NULL) 173 *((void**) prev) = *((void**) current); 174 heap->pages = mmRemoveFromList(heap->pages, hpage); 175 mmFreePage(hpage); 176 assume(mmListLength(heap->current) == l - (SIZE_OF_HEAP_PAGE / heap->size)); 177 mmCheckHeap(heap); 178 } 179 #else 180 void mmRemoveHeapBlocksOfPage(memHeap heap, memHeapPage hpage) 181 {} 182 #endif 183 184 #ifdef HAVE_AUTOMATIC_HEAP_COLLECTION 185 void _mmCleanHeap(memHeap heap) 186 #else 187 void mmCleanHeap(memHeap heap) 188 #endif 189 { 190 memHeapPage hpage = heap->pages; 191 void* current = heap->current; 192 int nblocks = SIZE_OF_HEAP_PAGE / (heap->size); 193 194 assume(heap != NULL); 195 mmCheckHeap(heap); 196 197 while (hpage != NULL) 198 { 199 hpage->counter = nblocks; 200 hpage = hpage->next; 201 } 202 203 while (current != NULL) 204 { 205 hpage = mmGetHeapPageOfAddr(current); 206 current = *((void**) current); 207 if (--(hpage->counter) == 0) 208 mmRemoveHeapBlocksOfPage(heap, hpage); 209 } 210 211 } 212 #else 213 void mmCleanHeap(memHeap heap) 214 { 215 assume(heap != NULL); 216 mmCheckHeap(heap); 217 218 if (mmListLength(heap->current) == 219 mmListLength(heap->pages) * (SIZE_OF_HEAP_PAGE / heap->size)) 220 mmClearHeap(heap); 221 mmCheckHeap(heap); 222 } 223 #endif 224 110 225 #ifdef HEAP_DEBUG 111 226 int mm_HEAP_DEBUG = HEAP_DEBUG; … … 124 239 { 125 240 void* page; 241 memHeapPage hpage; 126 242 127 243 if (heap == NULL) … … 140 256 #ifdef HAVE_PAGE_ALIGNMENT 141 257 page = mmGetPageOfAddr(addr); 142 258 143 259 if (! mmIsAddrOnList(page, heap->pages)) 144 260 return mmPrintHeapError("addr not on heap page", addr, heap, fn, l); … … 146 262 if ( (((long) (((char*) addr) - ((char*) page + SIZE_OF_HEAP_PAGE_HEADER))) 147 263 % heap->size) != 0) 148 return mmPrintHeapError("addr unaligned within heap", 149 addr, heap, fn, l); 150 #endif 264 return mmPrintHeapError("addr unaligned within heap", addr, heap, fn, l); 265 hpage = (memHeapPage) page; 266 #ifdef HAVE_AUTOMATIC_HEAP_COLLECTION 267 if (hpage->counter < 1) 268 return mmPrintHeapError("heap counter too small", addr, heap, fn, l); 269 #else 270 if (hpage->counter < 0) 271 return mmPrintHeapError("heap counter too small", addr, heap, fn, l); 272 #endif 273 #endif 151 274 return 1; 152 275 } … … 216 339 217 340 if (mm_HEAP_DEBUG > 1 && ! mmDebugCheckHeap(heap, fn, l)) 218 return 0;219 341 return NULL; 342 #if 0 220 343 _mmAllocHeap(res, heap); 344 #else 345 { 346 register memHeap _heap = heap ; 347 if ((_heap)->current == ((void *)0) ) mmAllocNewHeapPage(_heap); 348 do { register memHeapPage page = (memHeapPage) ((void*) ((long) ( (_heap)->current ) & ~(4096 -1))) ; 349 (page->counter)++; } while (0) ; 350 ((void*) ( res )) = (_heap)->current; 351 (_heap)->current = *((void**)(_heap)->current); 352 } 353 #endif 354 221 355 222 356 mmDebugCheckSingleHeapAddr(res, heap, fn, l); -
Singular/mmheap.h
r8e0123 rf8519e 4 4 * Computer Algebra System SINGULAR * 5 5 ****************************************/ 6 /* $Id: mmheap.h,v 1. 4 1998-12-16 18:43:41 SingularExp $ */6 /* $Id: mmheap.h,v 1.5 1999-01-26 14:41:40 obachman Exp $ */ 7 7 #include <stdlib.h> 8 #include "mod2.h" 8 9 #include "structs.h" 9 10 #include "mmpage.h" … … 13 14 extern "C" { 14 15 #endif 16 15 17 /***************************************************************** 16 18 * … … 18 20 * 19 21 *****************************************************************/ 20 struct sip_memHeap 21 { 22 void* current; 23 void* pages; 24 size_t size; 25 }; 22 /* define to enable automatic "garbage" collection of heaps */ 23 /* #define HAVE_AUTOMATIC_HEAP_COLLECTION */ 26 24 27 25 /***************************************************************** … … 30 28 * 31 29 *****************************************************************/ 32 30 33 31 /* Initializes Heap, assumes size < SIZE_OF_HEAP_PAGE */ 34 32 extern void mmInitHeap(memHeap heap, size_t size); 33 /* creates and initializes heap */ 34 extern memHeap mmCreateHeap(size_t size); 35 35 36 /* UNCONDITIONALLY frees all pages of heap */ 36 37 extern void mmClearHeap(memHeap heap); 38 /* UNCONDITIONALLY Clears and destroys heap */ 39 void mmDestroyHeap(memHeap *heap); 40 37 41 /* Tries to free as many unused pages of heap as possible */ 42 #if defined(HAVE_AUTOMATIC_HEAP_COLLECTION) && defined(HAVE_PAGE_ALIGNMENT) 43 /* CleanUpHeap does not do anything when automatic heap collection is on */ 44 #define mmCleanHeap(heap) 45 extern void _mmCleanHeap(memHeap heap); 46 #else 38 47 extern void mmCleanHeap(memHeap heap); 39 /* creates and initializes heap */ 40 extern memHeap mmCreateHeap(size_t size); 41 /* Clears and destroys heap */ 42 void mmDestroyHeap(memHeap *heap); 48 #endif 49 43 50 /* Merges what is free in Heap "what" into free list of heap "into" */ 44 51 void mmMergeHeap(memHeap into, memHeap what); 45 52 46 #define MM_HEAP_ADDR_UNKNOWN_FLAG 0 47 #define MM_HEAP_ADDR_USED_FLAG 1 48 #define MM_HEAP_ADDR_FREE_FLAG 2 53 /***************************************************************** 54 * 55 * Alloc, Free and Check for Heaps 56 * 57 *****************************************************************/ 49 58 50 59 #ifndef HEAP_DEBUG 51 60 52 #define mmAllocHeap _mmAllocHeap53 #define mmFreeHeap _mmFreeHeap61 #define mmAllocHeap(res, heap) _mmAllocHeap(res, heap) 62 #define mmFreeHeap(addr, heap) _mmFreeHeap(addr, heap) 54 63 55 64 #define mmCheckHeap(heap) 1 … … 61 70 (see mod2.h for details) */ 62 71 extern int mm_HEAP_DEBUG; 63 72 64 73 #define mmAllocHeap(res, heap)\ 65 74 ((void*)(res)) = mmDebugAllocHeap(heap, __FILE__, __LINE__) … … 75 84 76 85 #define mmCheckHeapAddr(addr, heap) \ 77 mmDebugCheckHeapAdr(addr, heap, MM_HEAP_ADDR_USED_FLAG, __FILE__, __LINE__) 86 mmDebugCheckHeapAdr(addr, heap, MM_HEAP_ADDR_USED_FLAG, __FILE__, __LINE__) 78 87 int mmDebugCheckHeapAddr(void* addr, memHeap heap, int flag, 79 88 const char* fn, int l); 80 89 81 90 #endif 82 91 … … 87 96 *****************************************************************/ 88 97 98 struct sip_memHeapPage; 99 typedef struct sip_memHeapPage * memHeapPage; 100 101 struct sip_memHeapPage 102 { 103 memHeapPage next; 104 long counter; 105 }; 106 107 struct sip_memHeap 108 { 109 void* current; 110 memHeapPage pages; 111 size_t size; 112 }; 113 114 115 116 #define SIZE_OF_HEAP_PAGE_HEADER (SIZEOF_VOIDP + SIZEOF_LONG) 117 118 #ifdef HAVE_PAGE_ALIGNMENT 119 120 #define mmGetHeapPageOfAddr(addr) (memHeapPage) mmGetPageOfAddr(addr) 121 122 #define mmIncrHeapPageCounterOfAddr(addr) \ 123 do \ 124 { \ 125 register memHeapPage page = mmGetHeapPageOfAddr(addr); \ 126 (page->counter)++; \ 127 } \ 128 while (0) 129 130 extern void mmRemoveHeapBlocksOfPage(memHeap heap, memHeapPage hpage); 131 132 #define mmDecrCurrentHeapPageCounter(heap) \ 133 do \ 134 { \ 135 register memHeapPage page = mmGetHeapPageOfAddr((heap)->current); \ 136 if (--(page->counter) == 0) mmRemoveHeapBlocksOfPage(heap, page); \ 137 } \ 138 while (0) 139 #endif /* HAVE_PAGE_ALIGNMENT */ 140 141 142 #define SIZE_OF_HEAP_PAGE (SIZE_OF_PAGE - SIZE_OF_HEAP_PAGE_HEADER) 143 #define mmGetHeapBlockSize(heap) ((heap)->size) 144 145 extern void mmAllocNewHeapPage(memHeap heap); 146 147 #if defined (HAVE_PAGE_ALIGNMENT) && defined(HAVE_AUTOMATIC_HEAP_COLLECTION) 89 148 /* Allocates memory block from a heap */ 90 149 #define _mmAllocHeap(what, heap) \ 91 150 do \ 92 151 { \ 93 if ((heap)->current == NULL) mmAllocNewHeapPage(heap); \ 94 ((void*) (what)) = (heap)->current; \ 95 (heap)->current = *((void**)(heap)->current); \ 152 register memHeap _heap = heap; \ 153 if ((_heap)->current == NULL) mmAllocNewHeapPage(_heap); \ 154 mmIncrHeapPageCounterOfAddr((_heap)->current); \ 155 ((void*) (what)) = (_heap)->current; \ 156 (_heap)->current = *((void**)(_heap)->current); \ 96 157 } \ 97 158 while (0) 98 159 99 /* Frees addr into heap, assumes addr was previously allocated from heap */ 100 #define _mmFreeHeap(addr, heap) 160 /* Frees addr into heap, assumes addr was previously allocated from heap */ 161 #define _mmFreeHeap(addr, heap) \ 101 162 do \ 102 163 { \ 103 *((void**) addr) = (heap)->current; \ 104 (heap)->current = (void*) addr; \ 164 register memHeap _heap = heap; \ 165 *((void**) addr) = (_heap)->current; \ 166 (_heap)->current = (void*) addr; \ 167 mmDecrCurrentHeapPageCounter(_heap); \ 105 168 } \ 106 169 while (0) 107 170 108 /***************************************************************** 109 * 110 * Auxillary routines 111 * 112 *****************************************************************/ 113 void 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) 171 #else 172 173 /* Allocates memory block from a heap */ 174 #define _mmAllocHeap(what, heap) \ 175 do \ 176 { \ 177 register memHeap _heap = heap; \ 178 if ((_heap)->current == NULL) mmAllocNewHeapPage(_heap); \ 179 ((void*) (what)) = (_heap)->current; \ 180 (_heap)->current = *((void**)(_heap)->current); \ 181 } \ 182 while (0) 183 184 /* Frees addr into heap, assumes addr was previously allocated from heap */ 185 #define _mmFreeHeap(addr, heap) \ 186 do \ 187 { \ 188 register memHeap _heap = heap; \ 189 *((void**) addr) = (_heap)->current; \ 190 (_heap)->current = (void*) addr; \ 191 } \ 192 while (0) 193 194 #endif /* defined(HAVE_PAGE_ALIGNMENT) && ... */ 195 196 #define MM_HEAP_ADDR_UNKNOWN_FLAG 0 197 #define MM_HEAP_ADDR_USED_FLAG 1 198 #define MM_HEAP_ADDR_FREE_FLAG 2 123 199 124 200 #ifdef __cplusplus -
Singular/mmisc.c
r8e0123 rf8519e 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: mmisc.c,v 1. 1 1998-12-02 13:57:34obachman Exp $ */4 /* $Id: mmisc.c,v 1.2 1999-01-26 14:41:41 obachman Exp $ */ 5 5 6 6 /* … … 143 143 **********************************************************************/ 144 144 145 void* mmRemoveFromList(void* list, void* element) 146 { 147 void* nlist; 148 void* olist; 149 150 if (list == NULL) return NULL; 151 152 nlist = *((void**) list); 153 olist = list; 154 155 if (list == element) return nlist; 156 157 while (nlist != NULL && nlist != element) 158 { 159 list = nlist; 160 nlist = *((void**) list); 161 } 162 163 if (nlist != NULL) *((void**) list) = *((void**) nlist); 164 165 return olist; 166 } 167 145 168 int mmListLength(void* list) 146 169 { -
Singular/mmprivate.h
r8e0123 rf8519e 4 4 * Computer Algebra System SINGULAR * 5 5 ****************************************/ 6 /* $Id: mmprivate.h,v 1. 3 1998-12-16 18:43:42 SingularExp $ */6 /* $Id: mmprivate.h,v 1.4 1999-01-26 14:41:41 obachman Exp $ */ 7 7 /* 8 8 * ABSTRACT … … 66 66 void mmFillDBMCB(DBMCB* what, size_t size, memHeap heap, 67 67 int flags, char* fname, int lineno); 68 void mmDBSetHeapsOfBlocks(memHeap fromheap, memHeap toheap); 69 void mmTakeOutDBMCB (DBMCB* what ); 70 void mmMoveDBMCB ( pDBMCB from, pDBMCB to, DBMCB * what ); 71 void mmMoveDBMCBInto ( pDBMCB to, pDBMCB what ); 72 68 73 #endif /* MDEBUG */ 69 74 -
Singular/mmtables.c
r8e0123 rf8519e 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: mmtables.c,v 1. 1 1998-12-02 13:57:37obachman Exp $ */4 /* $Id: mmtables.c,v 1.2 1999-01-26 14:41:42 obachman Exp $ */ 5 5 6 6 /* … … 16 16 #include <string.h> 17 17 #include "mod2.h" 18 #include "mmheap.h" 18 19 #include "mmemory.h" 19 20 #include "mmprivate.h" 20 21 #include "mmpage.h" 21 #include "mmheap.h"22 22 23 23
Note: See TracChangeset
for help on using the changeset viewer.