unsigned int nmemused
= 0;
unsigned int nmemavail
= 0;
ptr
alloc(), calloc(), malloc();
/*debug*/ if(n
>sizeof(struct genblock
)) fatal1("intalloc(%d)", n
);
if( (p
= calloc(1,n
)) == NULL
)
fatal1("Line %d: Cannot allocate memory", yylineno
);
/* Very stupid memory allocator. Stores a count word before
each block; negative if idle, positive if busy.
Looks for a block big enough for current request, and splits it
if necessary. Does not coalesce, always starts at bottom of memory.
Checks validity of all count words it encounters.
k
= (k
+ sizeof(int)-1) / sizeof(int);
if(k
<=0) fprintf(diagfile
, "alloc(%d words)\n", k
);
else if(k
>= NHISTO
) ++histo
[0];
if(k
> 256) fprintf(diagfile
, "calloc(%d words)\n", k
);
/* look for a large enough slot */
fprintf(diagfile
, "Bad count word %d\n", j
);
fprintf(diagfile
, "Bad count word %d\n", j
);
/* otherwise try to advance the fence */
/*debug*/ fprintf(diagfile
, "Highwater mark %d words. ", nmemused
);
/*debug*/ fprintf(diagfile
, "%ld words left over\n", totalloc
-totfreed
);
fatal1("Line %d: out of memory", yylineno
);
register unsigned int *p
;
if(p
<=mem
|| p
>mem
+nmemused
)
fprintf(diagfile
, "attempt to free an unallocated block, ");
fprintf(diagfile
, "attempted to free a block of length %u\n",p
[-1]);
bad
: fprintf(diagfile
, "location %o ", p
);
fprintf(diagfile
, "mem=%o lastused=%o\n", mem
, mem
+nmemused
);
/* if(p[-1]>256 || p[-1]<0) */
fprintf(diagfile
, "allocation histogram:\n%4d big blocks\n",histo
[0]);
if(histo
[i
]>0) fprintf(diagfile
, "%4d %2d-word blocks\n", histo
[i
],i
);
expblocks
= expblocks
->leftp
;
zeroout(p
, sizeof(struct exprblock
));
else return( ALLOC(exprblock
) );
if ( p
[-1] != sizeof(struct exprblock
)/sizeof(int) )
badtag("frexpblock", p
->tag
);
if(nexpblocks
< EXPRPOOL
)
excblocks
= excblocks
->leftp
;
zeroout(p
, sizeof(struct execblock
));
else return( ALLOC(execblock
) );
if( p
[-1] != sizeof(struct execblock
)/sizeof(int) )
fatal1("invalid frexcblock block of size %d", p
[-1]);
if(nexcblocks
< EXECPOOL
)
pn
= p
+ (n
+ sizeof(int)-1)/sizeof(int);
if(p0
==0 || *p0
==0) return;
for(p
= *p0
; p
->nextp
; p
= p
->nextp
)
fprintf(diagfile
, "Memory dump:\n");
fprintf(diagfile
, "Loc %6o = Word %5d ", mem
+i
, i
);
fprintf(diagfile
, "Idle block length %4d ", j
= -j
);
else fprintf(diagfile
, "Busy block length %4d ", j
);
fprintf(diagfile
, "tag %3d", mem
[i
+1].tag
);
if(mem
[i
+1].tag
==TNAME
&& mem
[i
+1].sthead
!=0)
fprintf(diagfile
, " varname %s", mem
[i
+1].sthead
->namep
);
fprintf(diagfile
, " chain %o %o", mem
[i
+1], mem
[i
+2]);
else if (mem
[i
+1].tag
> TIOSTAT
)
fprintf(diagfile
, " \"");