* from: malloc.c,v 2.2 88/09/19 12:55:18 nhall Exp
* This code is such a kludge that I don't want to put my name on it.
* It was a ridiculously fast hack and needs rewriting.
* However it does work...
* it might be brain-damaged but for the purposes of xebec
* it's a whole lot faster than the c library malloc
static char *hiwat
, *highend
;
hiwat
= (char *) sbrk(0);
hiwat
= (char *)((unsigned)(hiwat
+ 3) & ~0x3);
fprintf(stdout
, "HIWAT 0x%x %s\n", hiwat
,s
);
#define MIN(x,y) ((x<y)?x:y)
fprintf(stdout
, "Malloc 0x%x, %d, bytesmalloced %d\n",
total
,total
, bytesmalloced
);
fprintf(stdout
, "Malloc 0x%x, %d, hiwat 0x%x\n",
if(((unsigned)(hiwat
) & 0x3)) {
bytesmalloced
= 4 - (int) ((unsigned)(hiwat
) & 0x3);
hiwat
= sbrk( bytesmalloced
);
x
= MIN(CHUNKSIZE
, total
);
fprintf(stdout
, "BIG Malloc tot %d, x %d, left %d net %d\n",
total
,x
, total
-x
, bytesmalloced
);
if ( (hiwat
+ x
) > highend
) {
fprintf(stdout
, "hiwat 0x%x, x 0x%x, highend 0x%x, c 0x%x\n",
fprintf(stderr
, "Ran out of memory!\n");
bytesmalloced
+= CHUNKSIZE
;
fprintf(OUT
, "warning: %d wasted bytes!\n", highend
- hiwat
);
fprintf(OUT
, " chunksize 0x%x, x 0x%x \n", CHUNKSIZE
, x
);
if((unsigned)hiwat
& 0x3) {
byteswasted
+= (int)((unsigned)(hiwat
) & 0x3);
hiwat
= (char *)((unsigned)(hiwat
+ 3) & ~0x3);
fprintf(stdout
, "Malloc = 0x%x, bytesm 0x%x, wasted 0x%x, hiwat 0x%x\n",
returnvalue
, bytesmalloced
, byteswasted
, hiwat
);
fprintf(stdout
, "Malloc returns 0x%x, sbrk(0) 0x%x\n", returnvalue
, sbrk(0));