source: git/factory/mmspec.c @ 84250a6

spielwiese
Last change on this file since 84250a6 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: 3.0 KB
Line 
1/* emacs edit mode for this file is -*- C -*- */
2/* $Id: mmspec.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 <string.h>
11#include <stdio.h>
12#include <stdlib.h>
13#include "memman.h"
14#include "mmprivate.h"
15
16void
17mmMark( void )
18{
19    if ( mm_status != MM_NORMAL )
20        fprintf( stderr, "can only mark memory in status normal" );
21    else {
22        mm_status = MM_TMP;
23        mm_normList = mm_theList;
24        mm_theList = mm_tmpList;
25        mm_bytesNorm = mm_bytesUsed;
26        mm_bytesUsed = 0;
27#ifdef MDEBUG
28        mm_normDBused = mm_theDBused;
29        mm_normDBfree = mm_theDBfree;
30        memset(&mm_theDBused,0,sizeof(mm_theDBused));
31        memset(&mm_theDBfree,0,sizeof(mm_theDBfree));
32#endif /* MDEBUG */
33        mmMarkHeap(); mmMarkBlocks();
34    }
35}
36
37void
38mmSweep( void )
39{
40    int i;
41
42    if ( mm_status != MM_TMP )
43        fprintf( stderr, "can only sweep memory in status tmp" );
44    else {
45        mm_status = MM_NORMAL;
46        mm_theList = mm_normList;
47        mm_bytesUsed = mm_bytesNorm;
48        for ( i = 0; i < MAXLIST; i++ )
49            mm_tmpList[i] = NULL;
50#ifdef MDEBUG
51        mm_theDBused = mm_normDBused;
52        mm_theDBfree = mm_normDBfree;
53#endif /* MDEBUG */
54        mmSweepHeap(); mmSweepBlocks();
55    }
56}
57
58void
59mmSwitch( void )
60{
61    if ( mm_status == MM_NORMAL )
62        fprintf( stderr, "can not switch from state normal" );
63    else {
64        if ( mm_status == MM_SWITCHED ) {
65            mm_normList = mm_theList;
66            mm_theList = mm_tmpList;
67            mm_status = MM_TMP;
68            mm_bytesNorm = mm_bytesUsed;
69            mm_bytesUsed = mm_bytesTmp;
70#ifdef MDEBUG
71            mm_normDBfree = mm_theDBfree;
72            mm_normDBused = mm_theDBused;
73            mm_theDBfree = mm_tmpDBfree;
74            mm_theDBused = mm_tmpDBused;
75#endif /* MDEBUG */
76        }
77        else {
78            mm_tmpList = mm_theList;
79            mm_theList = mm_normList;
80            mm_status = MM_SWITCHED;
81            mm_bytesTmp = mm_bytesUsed;
82            mm_bytesUsed = mm_bytesNorm;
83#ifdef MDEBUG
84            mm_tmpDBfree = mm_theDBfree;
85            mm_tmpDBused = mm_theDBused;
86            mm_theDBfree = mm_normDBfree;
87            mm_theDBused = mm_normDBused;
88#endif /* MDEBUG */
89        }
90        mmSwitchHeap(); mmSwitchBlocks();
91    }
92}
93
94#ifndef MDEBUG
95char *
96mmStrdup( char * s )
97{
98    char * rc;
99    if (s==NULL) return NULL;
100    rc = (char*)mmAlloc( 1 + strlen( s ) );
101    strcpy( rc, s );
102    return rc;
103}
104#else
105char *
106mmDBStrdup( char * s, char *fname, int lineno)
107{
108    char * rc;
109    if (s==NULL) return NULL;
110    rc = (char*)mmDBAlloc( 1 + strlen( s ),fname,lineno );
111    strcpy( rc, s );
112    return rc;
113}
114#endif
115
116int
117mmMemReal( void )
118{
119    return mm_bytesReal;
120}
121
122int
123mmMemUsed( void )
124{
125    if ( mm_status == MM_TMP )
126        return mm_bytesUsed + mm_bytesNorm;
127    else if ( mm_status == MM_SWITCHED )
128        return mm_bytesUsed + mm_bytesTmp;
129    else
130        return mm_bytesUsed;
131}
132
133int mmOLdPrintMark=0;
134
135void
136mmCheckPrint( void )
137{
138    if ( mm_bytesReal > mm_printMark ) {
139        int i=(mm_bytesReal+1023)/1024;
140        if (i!=mmOLdPrintMark) {
141            fprintf( stdout, "[%dk]", i );
142            fflush( stdout );
143            mmOLdPrintMark=i;
144        }
145        mmNewPrintMark();
146    }
147}
148
149void
150mmNewPrintMark( void )
151{
152    mm_printMark = (mm_bytesReal / (100*1024) + 1) * 1024 * 100;
153}
Note: See TracBrowser for help on using the repository browser.