Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site ki4pv.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!hropus!ki4pv!tanner From: tanner@ki4pv.UUCP (Tanner Andrews) Newsgroups: net.unix,net.unix-wizards,net.arch,net.lang.c Subject: Re: get size of malloc'd object Message-ID: <6922@ki4pv.UUCP> Date: Tue, 24-Jun-86 10:21:15 EDT Article-I.D.: ki4pv.6922 Posted: Tue Jun 24 10:21:15 1986 Date-Received: Thu, 26-Jun-86 04:30:08 EDT References: <165@daisy.UUCP> <334@valid.UUCP> <2206@peora.UUCP>, <718@wjvax.wjvax.UUCP> Organization: CompuData South, DeLand Lines: 33 Xref: watmath net.unix:8387 net.unix-wizards:18600 net.arch:3572 net.lang.c:9577 The problem with alignments, it would appear to me, would be easily solved by allowing for the largest machine type, which should be double. Thus (cast the routine type as needed when you call it): /* allocate core -- must free using my_free() */ char *my_malloc(sz) short int sz; { register char *p; if (p = malloc(sz+sizeof(double))) { *((short int *)p) = sz; p += sizeof(double); } return(p); } /* size of allocated object -- works for any p such that p is return * value from my_malloc * which has not been my_free'd */ short int my_sizeof(p) char *p; { return(*((short int *)(p - sizeof(double))) } -- Tanner Andrews