From: Endlisnis Newsgroups: comp.os.msdos.djgpp Subject: Re: question to malloc and free Date: Fri, 28 Aug 1998 11:27:20 -0300 Organization: NBTel Internet Lines: 27 Message-ID: <35E6BE48.62C42B67@unb.ca> References: NNTP-Posting-Host: fctnts06c09.nbnet.nb.ca Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Salvador Eduardo Tropea (SET) wrote: > > I've read that the size of the block allocated by malloc/new is always > > a power of 2, and rounded up to one if it isn't (after adding it's few > > words). Why does it do this? This seems (to me) like it would waste about > > 1/2 the RAM allocated. > First: DJ did a new malloc included in v2.02 to solve it. > Now: You waste some *virtual memory* not physical so normally doesn't affect. > The reason malloc works in this way is because is *fast*, the blocks are > clasified by size, only 32 sizes and to satisfy a malloc request you just > need to check if one block is available (in linked list of blocks of this > size) or create a new one, no "heap walks" are needed (like in Borland's > malloc). > Of course there are better solutions like the one used by DJ in the last > malloc. That's a neat idea. I noticed that malloc/new/free/delete was really fast in DJGPP. I used it for an assignment that tried to show how it was faster to use a circular array for a queue rather than a linked list. The only problem was that under DJGPP, it was FASTER to use a linked list. My professor didn't believe me, I had to show him the executable before he would give me marks for the assignment. -- (\/) Endlisnis (\/) s257m AT unb DOT ca Endlisnis AT GeoCities DOT com Endlis AT nbnet DOT nb DOT ca