source: git/factory/mmspec.c @ 276c3f

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