🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4512

Alignment of malloc()

#4512
From: Michael Spertus
Date: Fri, 29 Dec 1995 21:26
15 lines
1176 bytes
Most MS Windows NT C and C++ compilers return malloc() only 32 bit aligned, 
presumably because the Windows NT GlobalAlloc() systems returns 32 bit aligned
arenas. The BYTE floating point benchmark varied by a factor of 3 on Pentium
systems depending on how the arrays are aligned. It would clearly be better
to align malloc() on 32 bit boundaries because it might be cast to a float *.

The Question: Is the usual practice of 32 bit alignment compliant?

The standard says that the return value of malloc() should be properly aligned
for all data type. On the one hand, code that uses floats will endure gross
performance penalties if it doesn't check alignment, and programmers shouldn't
have to align all their malloc()s. On the other hand, the code still runs, 
albeit inefficiently.

What do you think?
Technical Details
Message-ID: <DKDA7D.Kw7@midway.uchicago.edu>
Path: arc1-ca.pugleaf.net!vixen.cso.uiuc.edu!uchinews!news

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c
Path: arc1-ca.pugleaf.net!vixen.cso.uiuc.edu!uchinews!news
From: Michael Spertus<mps@geodesic.com>
Subject: Alignment of malloc()
X-Nntp-Posting-Host: ford.uchicago.edu
Message-ID: <DKDA7D.Kw7@midway.uchicago.edu>
Sender: news@midway.uchicago.edu (News Administrator)
Organization: Dept. of Mathematics
Date: Fri, 29 Dec 1995 21:26:01 GMT