|
|
1.1 ! root 1: /* list allocator */ ! 2: ! 3: typedef struct hdr { ! 4: struct hdr *next; ! 5: struct hdr **list; ! 6: short d[1]; ! 7: } hdr; ! 8: extern char *malloc(); ! 9: ! 10: hdr *h1, *h4, *h6; ! 11: ! 12: hfree(d) ! 13: short *d; ! 14: { hdr *p; ! 15: if(d == (short *)1) ! 16: return; ! 17: p = (hdr *)((char *)d - 2 * sizeof(hdr *)); ! 18: if(p->list == 0) { ! 19: free((char *)p); ! 20: return; ! 21: } ! 22: p->next = *p->list; ! 23: *p->list = p; ! 24: } ! 25: ! 26: short * ! 27: halloc(n) ! 28: { short *x; ! 29: hdr *p; ! 30: if(n <= 0) ! 31: return((short *)1); /* and unusable */ ! 32: if(n <= 2) { ! 33: if(!h1) ! 34: makelist(4, &h1); ! 35: x = h1->d; ! 36: h1 = h1->next; ! 37: return(x); ! 38: } ! 39: if(n <= 8) { ! 40: if(!h4) ! 41: makelist(16, &h4); ! 42: x = h4->d; ! 43: h4 = h4->next; ! 44: return(x); ! 45: } ! 46: if(n <= 64) { ! 47: if(!h6) ! 48: makelist(128, &h6); ! 49: x = h6->d; ! 50: h6 = h6->next; ! 51: return(x); ! 52: } ! 53: p = (hdr *) malloc(sizeof(hdr) + (n - 1) * sizeof(short)); ! 54: p->list = 0; ! 55: return(p->d); ! 56: } ! 57: ! 58: makelist(n, p) ! 59: hdr **p; ! 60: { int i, d; ! 61: char *s; ! 62: hdr *h; ! 63: d = sizeof(hdr) + sizeof(short) * (n-1); ! 64: d = (d + 3) & (~3); ! 65: s = malloc(128 * d); ! 66: h = *p = (hdr *)s; ! 67: for(i = 0; i < 127; i++) { ! 68: h->next = (hdr *)(s + d); ! 69: h->list = p; ! 70: s += d; ! 71: h = (hdr *)s; ! 72: } ! 73: h->next = 0; ! 74: h->list = p; ! 75: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.