Date: Thu, 24 Aug 2000 09:09:44 +0200 From: "Eli Zaretskii" Sender: halo1 AT zahav DOT net DOT il To: Leon AT caresystems DOT com DOT au Message-Id: <1659-Thu24Aug2000090944+0300-eliz@is.elta.co.il> X-Mailer: Emacs 20.6 (via feedmail 8.2.emacs20_6 I) and Blat ver 1.8.5b CC: djgpp AT delorie DOT com In-reply-to: <39A4EB1B.29871.12C6F4@localhost> (Leon@caresystems.com.au) Subject: Re: one more about memory alloc - free memory of needed amount only References: <39A4EB1B DOT 29871 DOT 12C6F4 AT localhost> Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk > From: Leon AT caresystems DOT com DOT au > Date: Thu, 24 Aug 2000 09:30:03 +1000 > > the problem is - how would one free memory that is a remainder of offset? > for example say malloc returns 5 (pseudo example only) so then one > modifies it to say 10... > now the memory from location 5 to location 9 is theoretically not used > and thus could be used when some other allocation needs to take place - > the thing is - how can i free memory from locaton 5 to location 9 > keeping the rest (from loc 10 to whatever was allocated)... You can't. The whole block must be freed as a single allocation. If your application really needs to release those unused small chunks, you will have to do your own allocation, for example, by allocating large blocks that are aligned as you wish, and then subdividing them as appropriate. When allocated blocks are large, the extra slack of a few bytes is not important. FWIW, most applications that need aligned memory don't need to bother about the slack at all, since the number of such allocations is usually small.