source: git/factory/mmheap.c @ ac7e53

fieker-DuValspielwiese
Last change on this file since ac7e53 was 2dd068, checked in by Rüdiger Stobbe <stobbe@…>, 28 years ago
Initial revision git-svn-id: file:///usr/local/Singular/svn/trunk@6 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.8 KB
Line 
1/* emacs edit mode for this file is -*- C -*- */
2/* $Id: mmheap.c,v 1.0 1996-05-17 10:59:48 stobbe Exp $ */
3
4/*
5$Log: not supported by cvs2svn $
6*/
7
8#define _POSIX_SOURCE 1
9
10#include <stdlib.h>
11#include "memman.h"
12#include "mmprivate.h"
13
14static char * mm_theHeapPtr = NULL;
15static char * mm_tmpHeapPtr = NULL;
16static char * mm_normHeapPtr = NULL;
17
18static int mm_theBytesLeft = 0;
19static int mm_tmpBytesLeft = 0;
20static int mm_normBytesLeft = 0;
21
22static status_t mm_heapStatus = MM_NORMAL;
23
24static void mmDistributeRestOfHeap( void );
25
26void
27mmInitHeap( void )
28{
29    mm_theHeapPtr = mm_tmpHeapPtr = mm_normHeapPtr = NULL;
30    mm_theBytesLeft = mm_tmpBytesLeft = mm_normBytesLeft = 0;
31    mm_heapStatus = MM_NORMAL;
32}
33
34void
35mmMarkHeap( void )
36{
37    mm_normHeapPtr = mm_theHeapPtr; mm_normBytesLeft = mm_theBytesLeft;
38    mm_theHeapPtr = NULL; mm_theBytesLeft = 0;
39    mm_heapStatus = MM_TMP;
40}
41
42void
43mmSweepHeap( void )
44{
45    mm_theHeapPtr = mm_normHeapPtr; mm_theBytesLeft = mm_normBytesLeft;
46    mm_heapStatus = MM_NORMAL;
47}
48
49void
50mmSwitchHeap( void )
51{
52    if ( mm_heapStatus == MM_TMP ) {
53        mm_heapStatus = MM_SWITCHED;
54        mm_tmpHeapPtr = mm_theHeapPtr; mm_tmpBytesLeft = mm_theBytesLeft;
55        mm_theHeapPtr = mm_normHeapPtr; mm_theBytesLeft = mm_normBytesLeft;
56    }
57    else {
58        mm_heapStatus = MM_TMP;
59        mm_normHeapPtr = mm_theHeapPtr; mm_normBytesLeft = mm_theBytesLeft;
60        mm_theHeapPtr = mm_tmpHeapPtr; mm_theBytesLeft = mm_tmpBytesLeft;
61    }
62}
63
64void *
65mmGetMemory( size_t size )
66{
67    void * dummy;
68
69    if ( mm_theBytesLeft < size ) {
70        mmDistributeRestOfHeap();
71        mm_theHeapPtr = (char*)mmGetBlock();
72        mm_theBytesLeft = MAXDATA;
73    }
74    dummy = (void*)mm_theHeapPtr;
75    mm_theBytesLeft -= size;
76    mm_theHeapPtr += size;
77    return dummy;
78}
79
80int
81mmPutMemory( void *adr, size_t size )
82{
83    void * dummy=(void *)((char *)adr+size);
84
85    if ( dummy == mm_theHeapPtr) {
86        mm_theHeapPtr=(char *)adr;
87        mm_theBytesLeft += size;
88        return 1; /*TRUE*/
89    }
90    return 0; /*FALSE*/
91}
92
93#ifndef MDEBUG
94
95void
96mmDistributeRestOfHeap( void )
97{
98/*
99  char* dummy;
100  int j;
101
102  while ( mm_theBytesLeft > RealSizeFromSize( mmGetSize( 0 ) ) ) {
103  j = mmGetIndex( SizeFromRealSize( mm_theBytesLeft ) );
104  if ( RealSizeFromSize( mmGetSize( j ) ) > mm_theBytesLeft ) j--;
105  dummy = mm_theHeapPtr;
106  mm_theHeapPtr += RealSizeFromSize( mmGetSize( j ) );
107  mm_theBytesLeft -= RealSizeFromSize( mmGetSize( j ) );
108  mmFreeBlock( &(dummy[DebugOffsetFront]), mmGetSize( j ) );
109  }
110  */
111}
112
113#else /* MDEBUG */
114
115void
116mmDistributeRestOfHeap( void )
117{
118/*
119  void* dummy;
120  int j;
121
122  while ( mm_theBytesLeft > RealSizeFromSize( mmGetSize( 0 ) ) ) {
123  j = mmGetIndex( SizeFromRealSize( mm_theBytesLeft ) );
124  if ( RealSizeFromSize( mmGetSize( j ) ) > mm_theBytesLeft ) j--;
125  dummy = mmAllocBlock( mmGetSize( j ) );
126  mmFreeBlock( &dummy, mmGetSize( j ) );
127  }
128  */
129}
130
131#endif /* MDEBUG */
Note: See TracBrowser for help on using the repository browser.