Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!ut-sally!seismo!harvard!cmcl2!philabs!pwa-b!mmintl!franka From: franka@mmintl.UUCP (Frank Adams) Newsgroups: net.unix,net.arch,net.lang.c Subject: Re: get size of malloc'd object Message-ID: <1615@mmintl.UUCP> Date: Mon, 30-Jun-86 19:14:41 EDT Article-I.D.: mmintl.1615 Posted: Mon Jun 30 19:14:41 1986 Date-Received: Thu, 3-Jul-86 00:42:31 EDT References: <165@daisy.UUCP> <334@valid.UUCP> <2206@peora.UUCP> <2081@umcp-cs.UUCP> <1043@umd5.UUCP> <2219@peora.UUCP> Reply-To: franka@mmintl.UUCP (Frank Adams) Organization: Multimate International, E. Hartford, CT Lines: 23 Xref: watmath net.unix:8485 net.arch:3641 net.lang.c:9692 In article <2219@peora.UUCP> jer@peora.UUCP writes: >> Yes, but I think there is a question whether you want to tell the user >> about 1. how much he ASKED for, or 2. how much happens to BE there... > >The only portable value is how much he asked for. If he got more than >that, it is just an artifact of the memory allocation scheme, which would >be implementation-dependent, and thus he shouldn't use it; allowing him to >know how much extra he really got is a step in the direction of promoting >him to use it, which would seem not to be a good idea. Depends on what you mean by "portable". Certainly, it is possible to use this number in an implementation-dependent way; but there are natural and non-implementation-dependent ways to use the information. E.g., if one is allocating character strings and one of them grows, one can try to fit the expanded string into the allocated size, and only reallocate (and reset all the pointers to the data) if it won't fit. The philosphy of C is to give the programmer access to information if there are reasonable ways to use it, not to try to withhold the information if there are unreasonable ways to use it. Frank Adams ihnp4!philabs!pwa-b!mmintl!franka Multimate International 52 Oakland Ave North E. Hartford, CT 06108