Annotation of 41BSD/cmd/apl/aq.c, revision 1.1.1.1

1.1       root        1: #
                      2: /*
                      3:  * C library -- alloc/free
                      4:  */
                      5: 
                      6: #define        logical int
                      7: 
                      8: struct fb {
                      9:        logical size;
                     10:        char    *next;
                     11: };
                     12: 
                     13: int    freelist[] = {
                     14:        0,
                     15:        -1,
                     16: };
                     17: logical        slop    = 2;
                     18: 
                     19: alloc(asize)
                     20: logical asize;
                     21: { return ( calloc ( 1 , asize ) ); }  
                     22: /*{
                     23:        register logical size;
                     24:        register logical np;
                     25:        register logical cp;
                     26: 
                     27:        if ((size = asize) == 0)
                     28:                return(0);
                     29:        size += 3;
                     30:        size &= ~01;
                     31:        for (;;) {
                     32:                cp = freelist;
                     33:                while ((np = cp->next) != -1) {
                     34:                        if (np->size>=size) {
                     35:                                if (size+slop >= np->size) {
                     36:                                        cp->next = np->next;
                     37:                                        return(&np->next);
                     38:                                }
                     39:                                cp = cp->next = np+size;
                     40:                                cp->size = np->size - size;
                     41:                                cp->next = np->next;
                     42:                                np->size = size;
                     43:                                return(&np->next);
                     44:                        }
                     45:                        cp = np;
                     46:                }
                     47:                return ( calloc ( 1 , asize ) ); 
                     48: 
                     49:                /* asize = size<1024? 1024: size;
                     50:                if ((cp = sbrk(asize)) == -1) {
                     51:                        error("workspace exceeded");
                     52: 
                     53:                }
                     54:                cp->size = asize;
                     55:                free(&cp->next); 
                     56:        }
                     57: }  */
                     58: 
                     59: 
                     60: afree(aptr)
                     61: char *aptr;
                     62: {if ( aptr == 0 ) return;
                     63: cfree ( aptr ); }  
                     64: /* {
                     65:        register logical ptr;
                     66:        register logical cp;
                     67:        register logical np;
                     68: 
                     69:        if (aptr == 0) return;
                     70:        ptr = aptr-4;
                     71:        cp = freelist;
                     72:        while ((np = cp->next) < ptr)
                     73:                cp = np;
                     74:        if (ptr+ptr->size == np) {
                     75:                ptr->size += np->size;
                     76:                ptr->next = np->next;
                     77:                np = ptr;
                     78:        } else
                     79:                ptr->next = np;
                     80:        if (cp+cp->size == ptr) {
                     81:                cp->size += ptr->size;
                     82:                cp->next = ptr->next;
                     83:        } else
                     84:                cp->next = ptr;
                     85: } */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.