Changeset f8519e in git


Ignore:
Timestamp:
Jan 26, 1999, 3:41:42 PM (25 years ago)
Author:
Olaf Bachmann <obachman@…>
Branches:
(u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
Children:
b6285e707366fbd4f332d38d696bd74910bcbe9e
Parents:
8e012379f6186bcc208b49f8710913df381eb5e3
Message:
* added AllocAligned & FreeAligned


git-svn-id: file:///usr/local/Singular/svn/trunk@2816 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
Singular
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • Singular/mmalloc.c

    r8e0123 rf8519e  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: mmalloc.c,v 1.10 1999-01-18 17:28:05 Singular Exp $ */
     4/* $Id: mmalloc.c,v 1.11 1999-01-26 14:41:38 obachman Exp $ */
    55
    66/*
     
    2222#include "mmprivate.h"
    2323
     24#undef HAVE_ASSUME
     25#define HAVE_ASSUME
    2426
    2527#ifndef MDEBUG
     
    166168
    167169#else /* MDEBUG */
    168 
    169 /**********************************************************************
    170  *
    171  * Auxillary routines
    172  *
    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 }
    224170
    225171/**********************************************************************
     
    361307    }
    362308    mm_bytesMalloc -= tmpsize;
    363     mmTakeOutDBMCB( &mm_theDBused, what );
     309    mmTakeOutDBMCB(what );
    364310    free( what );
    365311    if (BVERBOSE(V_SHOW_MEM)) mmCheckPrint();
     
    458404#if SIZEOF_DOUBLE == SIZEOF_VOIDP + SIZEOF_VOIDP
    459405
    460 #if 0
    461406#ifdef MDEBUG
    462407void * mmDBAllocAlignedBlock( size_t size, char* f, int l)   
     
    470415  {
    471416#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);
    475422#endif
    476423    unsigned char shift = (ret + 1) & (SIZEOF_DOUBLE - 1);
     
    478425
    479426    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;
    482432  }
    483433  else
     
    537487  void* good;
    538488#ifdef MDEBUG
    539   good = mmDBAllocBlock(size, f, l);
    540 #else
    541   good = mmAllocBlock(size);
     489  good = mmDBAllocAllignedBlock(size, f, l);
     490#else
     491  good = mmAllocAlignedBlock(size);
    542492#endif
    543493 
     
    554504{
    555505  int i = mmGetIndex(size);
     506
     507  assume((unsigned long) addr % SIZEOF_DOUBLE == 0);
    556508 
    557509  if (i < 0)
     
    561513
    562514#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);
    566518#endif
    567519  }
     
    575527  }
    576528}
    577 #endif
    578529
    579530#endif /* SIZEOF_DOUBLE == SIZEOF_VOIDP + SIZEOF_VOIDP */
  • Singular/mmcheck.c

    r8e0123 rf8519e  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: mmcheck.c,v 1.2 1999-01-05 12:18:39 Singular Exp $ */
     4/* $Id: mmcheck.c,v 1.3 1999-01-26 14:41:38 obachman Exp $ */
    55
    66/*
     
    3838 *
    3939 **********************************************************************/
     40
     41void 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
     53void 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
     64void mmTakeOutDBMCB ( pDBMCB what )
     65{
     66  what->prev->next = what->next;
     67  if ( what->next != NULL )
     68    what->next->prev = what->prev;
     69}
     70
     71void 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
     91void 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}
    40111
    41112static int mmPrintDBMCB ( DBMCB * what, char* msg , int given_size)
  • Singular/mmemory.h

    r8e0123 rf8519e  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: mmemory.h,v 1.14 1998-12-18 11:11:38 obachman Exp $ */
     6/* $Id: mmemory.h,v 1.15 1999-01-26 14:41:39 obachman Exp $ */
    77/*
    88* ABSTRACT
     
    3434void   mmFree( void* );
    3535char * mmStrdup( const char* );
    36 #if 0 /* Alligned Allloc does not work, yet */
    3736void * mmAllocAlignedBlock( size_t );
    3837void * mmAllocAlignedBlock0( size_t );
    39 void * mmFreeAlignedBlock( void*, size_t );
    40 #endif
     38void   mmFreeAlignedBlock( void*, size_t );
    4139
    4240#define AllocHeap               mmAllocHeap
     
    5048#define AllocL                  mmAlloc
    5149#define mstrdup                 mmStrdup
    52 #if 0
    5350#define AllocAligned0           mmAllocAlignedBlock0
    5451#define AllocAligned            mmAllocAlignedBlock
    5552#define FreeAligned             mmFreeAlignedBlock
    56 #endif
    5753
    5854#else /* MDEBUG */
     
    6965void   mmDBFree( void*, char*, int );
    7066char * mmDBStrdup( const char * s, char *fname, int lineno);
    71 #if 0
    7267void * mmDBAllocAlignedBlock( size_t, char*, int );
    7368void * mmDBAllocAlignedBlock0( size_t,  char*, int);
    74 void * mmDBFreeAlignedBlock( void*, size_t, char*, int );
    75 #endif
     69void   mmDBFreeAlignedBlock( void*, size_t, char*, int );
    7670
    7771#define AllocHeap(res, heap)\
     
    8781#define FreeL(a)                mmDBFree(a,__FILE__,__LINE__)
    8882#define mstrdup(s)              mmDBStrdup(s, __FILE__, __LINE__)
    89 #if 0
    9083#define AllocAligned(s)         mmDBAllocAlignedBlock(s, __FILE__, __LINE__)
    9184#define AllocAligned0(s)        mmDBAllocAlignedBlock0(s, __FILE__, __LINE__)
    9285#define FreeAligned(a,s)        mmDBFreeAlignedBlock(a, s, __FILE__, __LINE__)
    93 #endif
    9486
    9587#endif /* MDEBUG */
     
    167159 **********************************************************************/
    168160/* The following routines assume that Next(list) == *((void**) list) */
    169 
     161/* Removes element from list, if contained in it and returns list */
     162void* mmRemoveFromList(void* list, void* element);
    170163/* Returns the length of a memory list; assumes list has no cycles */
    171164int mmListLength(void* list);
  • Singular/mmheap.c

    r8e0123 rf8519e  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: mmheap.c,v 1.7 1998-12-02 13:57:33 obachman Exp $ */
     4/* $Id: mmheap.c,v 1.8 1999-01-26 14:41:40 obachman Exp $ */
    55
    66#include "mod2.h"
     
    3838void mmClearHeap(memHeap heap)
    3939{
    40   void* page ;
    41   void* next_page;
     40  memHeapPage page, next_page;
    4241
    4342  mmCheckHeap(heap);
     
    4746  while(page != NULL)
    4847  {
    49     next_page = mmGetPageOfAddr(*((void**) page));
    50     mmFreePage(page);
     48    next_page = page->next;
     49    mmFreePage((void*) page);
    5150    page = next_page;
    5251  }
     
    5756void mmAllocNewHeapPage(memHeap heap)
    5857{
    59   void* newpage = mmGetPage();
     58  memHeapPage newpage = (memHeapPage) mmGetPage();
    6059  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;
    6566  heap->pages = newpage;
    6667 
    67   heap->current = (void*) (((char*)newpage) + SIZEOF_VOIDP);
    68   newpage = heap->current;
     68  heap->current = (void*) (((char*)newpage) + SIZE_OF_HEAP_PAGE_HEADER);
     69  tmp = heap->current;
    6970
    7071  while (i < n)
    7172  {
    72     *((void**)newpage) = (void*) (((char*)newpage) + heap->size);
    73     newpage = *((void**)newpage);
     73    *((void**)tmp) = (void*) (((char*)tmp) + heap->size);
     74    tmp = *((void**)tmp);
    7475    i++;
    7576  }
    76   *((void**)newpage) = NULL;
     77  *((void**)tmp) = NULL;
    7778#ifdef MDEBUG
    7879  mmDBInitNewHeapPage(heap);
     
    8788
    8889  if (into == what) return;
     90#ifdef MDEBUG
     91  mmDBSetHeapsOfBlocks(what, into);
     92#endif 
    8993
    9094  if (what->pages != NULL)
     
    108112}
    109113
     114#ifdef HAVE_PAGE_ALIGNMENT
     115#if 1
     116void 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
     180void mmRemoveHeapBlocksOfPage(memHeap heap, memHeapPage hpage)
     181{}
     182#endif
     183
     184#ifdef HAVE_AUTOMATIC_HEAP_COLLECTION
     185void _mmCleanHeap(memHeap heap)
     186#else
     187void 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
     213void 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
    110225#ifdef HEAP_DEBUG
    111226int mm_HEAP_DEBUG = HEAP_DEBUG;
     
    124239{
    125240  void* page;
     241  memHeapPage hpage;
    126242 
    127243  if (heap == NULL)
     
    140256#ifdef HAVE_PAGE_ALIGNMENT
    141257  page = mmGetPageOfAddr(addr);
    142 
     258 
    143259  if (! mmIsAddrOnList(page, heap->pages))
    144260    return mmPrintHeapError("addr not on heap page", addr, heap, fn, l);
     
    146262  if ( (((long) (((char*) addr) - ((char*) page + SIZE_OF_HEAP_PAGE_HEADER)))
    147263        % 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
    151274  return 1;
    152275}
     
    216339
    217340  if (mm_HEAP_DEBUG > 1 && ! mmDebugCheckHeap(heap, fn, l))
    218     return 0;
    219  
     341    return NULL;
     342#if 0 
    220343  _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
    221355
    222356  mmDebugCheckSingleHeapAddr(res, heap, fn, l);
  • Singular/mmheap.h

    r8e0123 rf8519e  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: mmheap.h,v 1.4 1998-12-16 18:43:41 Singular Exp $ */
     6/* $Id: mmheap.h,v 1.5 1999-01-26 14:41:40 obachman Exp $ */
    77#include <stdlib.h>
     8#include "mod2.h"
    89#include "structs.h"
    910#include "mmpage.h"
     
    1314extern "C" {
    1415#endif
     16
    1517/*****************************************************************
    1618 *
     
    1820 *
    1921 *****************************************************************/
    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 */
    2624
    2725/*****************************************************************
     
    3028 *
    3129 *****************************************************************/
    32 
     30 
    3331/* Initializes Heap, assumes size < SIZE_OF_HEAP_PAGE */
    3432extern void mmInitHeap(memHeap heap, size_t size);
     33/* creates and initializes heap */
     34extern memHeap mmCreateHeap(size_t size);
     35
    3536/* UNCONDITIONALLY frees all pages of heap */
    3637extern void mmClearHeap(memHeap heap);
     38/* UNCONDITIONALLY Clears and destroys heap */
     39void mmDestroyHeap(memHeap *heap);
     40
    3741/* 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)
     45extern void _mmCleanHeap(memHeap heap);
     46#else
    3847extern 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
    4350/* Merges what is free in Heap "what" into free list of heap "into" */
    4451void mmMergeHeap(memHeap into, memHeap what);
    4552
    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 *****************************************************************/
    4958
    5059#ifndef HEAP_DEBUG
    5160
    52 #define mmAllocHeap               _mmAllocHeap
    53 #define mmFreeHeap                _mmFreeHeap
     61#define mmAllocHeap(res, heap)  _mmAllocHeap(res, heap)
     62#define mmFreeHeap(addr, heap) _mmFreeHeap(addr, heap)
    5463
    5564#define mmCheckHeap(heap)           1
     
    6170   (see mod2.h for details) */
    6271extern int mm_HEAP_DEBUG;
    63 
     72 
    6473#define mmAllocHeap(res, heap)\
    6574  ((void*)(res)) = mmDebugAllocHeap(heap, __FILE__, __LINE__)
     
    7584
    7685#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__) 
    7887int mmDebugCheckHeapAddr(void* addr, memHeap heap, int flag,
    7988                         const char* fn, int l);
    80 
     89 
    8190#endif
    8291
     
    8796 *****************************************************************/
    8897
     98struct sip_memHeapPage;
     99typedef struct sip_memHeapPage * memHeapPage;
     100
     101struct sip_memHeapPage
     102{
     103  memHeapPage next;
     104  long counter;
     105};
     106
     107struct 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)       \
     123do                                              \
     124{                                               \
     125  register memHeapPage page = mmGetHeapPageOfAddr(addr); \
     126  (page->counter)++;                            \
     127}                                               \
     128while (0)
     129
     130extern void mmRemoveHeapBlocksOfPage(memHeap heap, memHeapPage hpage);
     131
     132#define mmDecrCurrentHeapPageCounter(heap)                          \
     133do                                                                  \
     134{                                                                   \
     135  register memHeapPage page = mmGetHeapPageOfAddr((heap)->current); \
     136  if (--(page->counter) == 0) mmRemoveHeapBlocksOfPage(heap, page); \
     137}                                                                   \
     138while (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
     145extern void mmAllocNewHeapPage(memHeap heap);
     146
     147#if defined (HAVE_PAGE_ALIGNMENT) && defined(HAVE_AUTOMATIC_HEAP_COLLECTION)
    89148/* Allocates memory block from a heap */
    90149#define _mmAllocHeap(what, heap)                            \
    91150do                                                          \
    92151{                                                           \
    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);          \
    96157}                                                           \
    97158while (0)
    98159
    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)                 \
    101162do                                              \
    102163{                                               \
    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);          \
    105168}                                               \
    106169while (0)
    107170
    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)                            \
     175do                                                          \
     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}                                                           \
     182while (0)
     183
     184/* Frees addr into heap, assumes  addr was previously allocated from heap */
     185#define _mmFreeHeap(addr, heap)                \
     186do                                              \
     187{                                               \
     188  register memHeap _heap = heap;                \
     189  *((void**) addr) = (_heap)->current;          \
     190  (_heap)->current = (void*) addr;              \
     191}                                               \
     192while (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
    123199
    124200#ifdef __cplusplus
  • Singular/mmisc.c

    r8e0123 rf8519e  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: mmisc.c,v 1.1 1998-12-02 13:57:34 obachman Exp $ */
     4/* $Id: mmisc.c,v 1.2 1999-01-26 14:41:41 obachman Exp $ */
    55
    66/*
     
    143143 **********************************************************************/
    144144
     145void* 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
    145168int mmListLength(void* list)
    146169{
  • Singular/mmprivate.h

    r8e0123 rf8519e  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: mmprivate.h,v 1.3 1998-12-16 18:43:42 Singular Exp $ */
     6/* $Id: mmprivate.h,v 1.4 1999-01-26 14:41:41 obachman Exp $ */
    77/*
    88* ABSTRACT
     
    6666void mmFillDBMCB(DBMCB* what, size_t size, memHeap heap,
    6767                 int flags, char* fname, int lineno);
     68void mmDBSetHeapsOfBlocks(memHeap fromheap, memHeap toheap);
     69void mmTakeOutDBMCB (DBMCB* what );
     70void mmMoveDBMCB ( pDBMCB from, pDBMCB to, DBMCB * what );
     71void mmMoveDBMCBInto ( pDBMCB to, pDBMCB what );
     72
    6873#endif /* MDEBUG */
    6974
  • Singular/mmtables.c

    r8e0123 rf8519e  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: mmtables.c,v 1.1 1998-12-02 13:57:37 obachman Exp $ */
     4/* $Id: mmtables.c,v 1.2 1999-01-26 14:41:42 obachman Exp $ */
    55
    66/*
     
    1616#include <string.h>
    1717#include "mod2.h"
     18#include "mmheap.h"
    1819#include "mmemory.h"
    1920#include "mmprivate.h"
    2021#include "mmpage.h"
    21 #include "mmheap.h"
    2222
    2323
Note: See TracChangeset for help on using the changeset viewer.