Path: utzoo!mnetor!uunet!nuchat!steve From: steve@nuchat.UUCP (Steve Nuchia) Newsgroups: comp.unix.microport Subject: Re: Info needed: UNIX for 286/386 machines (really malloc) Message-ID: <777@nuchat.UUCP> Date: 12 Mar 88 15:07:12 GMT References: <427@micropen> Organization: Public Access - Houston, Tx Lines: 56 Re: flamage about the 286 malloc. It really is a crock. I looked into it and wrote the following allocator in support of pathalias, and it works with good efficiency (both space and time). If someone wants to layer the free() logic, say from K&R, on top of this it would make a very usable replacement. This only applies to large model, since sbrk isn't broken in small model (small consolation). -- /* * a primitive malloc replacement that works efficiently * in spite of the braindamage in uPort's brk/sbrk. * * This routine does not support a free() call. Recommend * someone layer a reasonable alloc/free package on top * of this system interface routine and repost it. * * Steve Nuchia * released to the public domain * 12 March 1988 * steve@nuchat (713) 334 6720 */ char *malloc(n) unsigned n; { static struct { char *p; unsigned s; } seg[64]; static int ns; register int i; if ( n & 1 ) n++; for ( i = 0; i < ns; i++ ) if ( seg[i].s >= n ) break; if ( i == ns ) { if ( ++ns > 64 ) abort(); seg[i].p = sbrk(0); seg[i].s = 0x0F000; if ( n > seg[i].s ) seg[i].s = n; while ( seg[i].s && brk(seg[i].p + seg[i].s) == -1 ) seg[i].s -= 512; seg[i].p[0] = seg[i].p[seg[i].s - 1] = 0; } seg[i].s -= n; seg[i].p += n; return ( seg[i].p - n ); } -- Steve Nuchia | [...] but the machine would probably be allowed no mercy. uunet!nuchat!steve | In other words then, if a machine is expected to be (713) 334 6720 | infallible, it cannot be intelligent. - Alan Turing, 1947