Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site alice.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!alice!ark From: ark@alice.UucP (Andrew Koenig) Newsgroups: net.unix,net.unix-wizards,net.arch,net.lang.c Subject: Re: get size of malloc'd object Message-ID: <5699@alice.uUCp> Date: Mon, 23-Jun-86 22:23:14 EDT Article-I.D.: alice.5699 Posted: Mon Jun 23 22:23:14 1986 Date-Received: Wed, 25-Jun-86 04:46:30 EDT References: <2216@peora.UUCP> Organization: Bell Labs, Murray Hill Lines: 28 Xref: watmath net.unix:8363 net.unix-wizards:18582 net.arch:3558 net.lang.c:9566 There is a very simple way to do this portably: struct chunk { unsigned size; char *mem; }; struct chunk challoc (n) unsigned n; { struct chunk ch; ch.size = n; ch.mem = malloc (n); return ch; } void chfree (ch) struct chunk ch; { if (ch.mem) free (ch.mem); } Now rewrite your program to deal with memory through chunk structures instead of through simple pointers. It should be possible to make this easier by using macros.