File: gcword.c

package info (click to toggle)
qepcad 1.74%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,848 kB
  • sloc: ansic: 27,242; cpp: 2,995; makefile: 1,287; perl: 91
file content (70 lines) | stat: -rw-r--r-- 1,816 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/***************************************************************
***
*** gcword.cc
***
*** This file implements the gcw_MARK() function, which is called
*** by the modified saclib garbage collector in order to account
*** for saclib Words pointed to by GCWord objects.
***
*** This file implements the gcw_register(p) function, which is
*** called upon creation and upon destuction of a GCWord object.
*** Each call adds p, the address of the GCWord, to the vector G,
*** so that if a given address occurs an odd number of times, it
*** contains a live GCWord object ... which the garbage collector
*** needs to consider.
***
*** The clean() function modifies vector G so that an address
*** appears in G after the call if and only if it appeared an odd
*** number of times before the call, and no address appears more
*** than once after the call.
***
*** CWB 5/15/00
***************************************************************/
#include <vector>
#include <algorithm>
#include "gcword.h"
using namespace std;

extern "C" {
void gcw_MARK();
}

static vector<Word*> G;
static int lim = 10;

void clean()
{
  //-- a hack to ensure that lim ends up being NU -------------//
  if (lim < NU) lim = NU;

  sort(G.begin(),G.end());

  //-- compacts sorted array by ignoring double values --------//
  int i,j,N = G.size()-1;
  for(i = 0; i < N; i++)
    if (G[i] == G[i+1]) {
      G[i] = G[i+1] = 0;
      i++; }
  for(i = 0, j = 0; j <= N; j++)
    if (G[j] != 0)
      swap(G[i++],G[j]);
  G.resize(i);
}

void gcw_register(Word *p)
{
  G.push_back(p);
  if (G.size() == (size_t)lim)
    clean();
}

void gcw_MARK()
{
  //  SWRITE("gcw size is: ");IWRITE(G.size()); SWRITE("\n");
  clean();
  for(size_t i = 0; i < G.size(); i++)
    if (*G[i] > BETA && *G[i] < BETAp && (*G[i] & 1))
      MARK(*G[i]);

  return;
}