www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/31/09:33:21

From: frenchc AT cadvision DOT com (Calvin French)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: mem alloc taking up power of 2
Date: 27 Jul 1997 20:40:10 GMT
Organization: CADVision Development Corp.
Lines: 25
Message-ID: <5rgbna$j1u@elmo.cadvision.com>
References: <1 DOT 5 DOT 4 DOT 16 DOT 19970727141631 DOT 54172988 AT giasbga DOT vsnl DOT net DOT in>
NNTP-Posting-Host: ts9ip88.cadvision.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <1 DOT 5 DOT 4 DOT 16 DOT 19970727141631 DOT 54172988 AT giasbga DOT vsnl DOT net DOT in>, 
chirayu AT radiolink DOT net says...

Not really following the thread, but I'm pretty sure it returns the two 
aligned, not the power-of-two aligned. Maybe even the four-aligned. This is 
to speed memory acesses, since even mem addresses work about twice as fast 
as odd, or at least they used to, and just about the same holds true for 
those divisible by 2 and 4. AFIAK, anyways... Oh, this should be fairly 
standard across all compilers. Incidently, for this same reason it is a good 
idea to place larger datatypes (ints/shorts) at the beginning of a data 
structure, and the smaller ones at the end (shorts/bytes). Should speed 
things up. OH! Yes, and I think that gcc may even optimize things this way, 
so that for instance if you use inheritance it will padd the existing 
structure to a 4-aligned -- but i'm guessing here so I should prolly just 
shut up while i'm still probably right! No need for concern, at any rate...

- Calvin -

>>But that's NOT correct. malloc() returns also the power of two aligned
>>block to the user.
>
>Now that is sheer wasting of memory. I think its a very bad idea to have
>implememnted it this way (the malloc()). Do the other compilers (watcom,
>visual c++, symantec etc) do the same?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019