Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!princeton!caip!lll-crg!nike!ucbcad!ucbvax!brahms!desj From: desj@brahms.BERKELEY.EDU (David desJardins) Newsgroups: net.unix,net.unix-wizards,net.arch,net.lang.c Subject: Re: get size of malloc'd object Message-ID: <14533@ucbvax.BERKELEY.EDU> Date: Mon, 23-Jun-86 21:09:53 EDT Article-I.D.: ucbvax.14533 Posted: Mon Jun 23 21:09:53 1986 Date-Received: Wed, 25-Jun-86 06:30:36 EDT References: <165@daisy.UUCP> <334@valid.UUCP> <2206@peora.UUCP> <2081@umcp-cs.UUCP> <2216@peora.UUCP> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: desj@brahms.UUCP (David desJardins) Organization: University of California, Berkeley Lines: 15 Xref: watmath net.unix:8372 net.unix-wizards:18586 net.arch:3563 net.lang.c:9571 I can't believe all of this discussion about clever tricks to try to guess how malloc does alignment, or what the maximum alignment boundary is, or whatever. No matter what you do along these lines, it is going to be possible to devise a perfectly valid C implementation in which it will fail. It seems obvious that the solution to the whole problem is to define a structure which contains two fields: the pointer to memory returned by malloc, and an int (or long int, or whatever) which contains the size of the block requested from malloc. This is guaranteed to work, as opposed to the many alternate implementations that have been proposed and are guaranteed to fail on at least some architectures. Note that in a strongly-typed language you would have had to do the right thing from the beginning... -- David desJardins