Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!houxm!hjuxa!petsd!peora!jer From: jer@peora.UUCP (J. Eric Roskos) Newsgroups: net.unix,net.unix-wizards,net.arch,net.lang.c Subject: Re: get size of malloc'd object Message-ID: <2206@peora.UUCP> Date: Tue, 17-Jun-86 08:57:04 EDT Article-I.D.: peora.2206 Posted: Tue Jun 17 08:57:04 1986 Date-Received: Thu, 19-Jun-86 07:28:15 EDT References: <165@daisy.UUCP> <334@valid.UUCP> Organization: Concurrent Computer Corporation, Orlando, Fl Lines: 24 Xref: watmath net.unix:8199 net.unix-wizards:18439 net.arch:3481 net.lang.c:9447 It is really hard to come up which general purpose algorithmic solutions to problems without having even a glimmer of what environment you are talking about ... Sure it is. Just write your own routine to call malloc; allocate a sizeof(int) worth of extra space, then store the size of the thing you malloc'ed in the int at the front of the allocated block, advance the pointer past the place where your stored the size, and return that as the pointer to the block you allocated. The size of the object is then found in the word preceeding the location pointed to by the object pointer. Also provide a routine to deallocate the block by backing the pointer up before calling free(). This approach is portable, simple, and easy to understand. Also it doesn't require any assumptions about what kind of objects are being allocated. -- E. Roskos "They are a nexus of commercially produced artifact and individual message that expresses a dialect central to popular culture." -- Sociologist explaining the reason for having Florida postcards.