Article View: comp.std.c
Article #4576Re: Alignment of malloc()
From: Lawrence Kirby
Date: Sat, 06 Jan 1996 18:29
Date: Sat, 06 Jan 1996 18:29
43 lines
1886 bytes
1886 bytes
In article <DKp9L9.234@ukpsshp1.serigate.philips.nl>
baynes@ukpsshp1.serigate.philips.nl "Stephen Baynes" writes:
>This reminds me of a discussion over could calloc use the size parameter
>as a hint to give different alignment to malloc. For example:
> calloc( N, sizeof( float ) )
>could recognize the sizeof float and give 64 bit alignment in this case.
>I recall the conclusion was that it could do this, but did not have to.
#include <stdio.h>
#include <stdlib.h>
#define NELEMS 500
int main(void)
{
long *squares = calloc(NELEMS * sizeof(long), 1);
if (squares != NULL) {
int ind;
for (ind = 0; ind < NELEMS; ind++)
squares[ind] = (long)ind * ind;
for (ind = 0; ind < NELEMS; ind++)
printf("%ld\n", squares[ind]);
free(squares);
}
return 0;
}
A conforming implementation must compile and run this program correctly.
Of course it could use such a 'hint' where the only result of sub-optimal
alignment is a performance hit.
--
-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------
Technical Details
Message-ID:
<820952976snz@genesis.demon.co.uk>Path:
arc1-ca.pugleaf.net!mail2news.demon.co.uk!genesis.demon.co.ukReferences:
<DKDA7D.Kw7@midway.uchicago.edu> <j66Sx*FRe@yaps.rhein.de> <DKKHCH.L6r@midway.uchicago.edu> <4ccbdb$5v6@fg70.rz.uni-karlsruhe.de> <DKo8ns.8A9@midway.uchicago.edu> <DKp9L9.234@ukpsshp1.serigate.philips.nl>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!mail2news.demon.co.uk!genesis.demon.co.uk From: Lawrence Kirby <fred@genesis.demon.co.uk> Newsgroups: comp.std.c Subject: Re: Alignment of malloc() Date: Sat, 06 Jan 96 18:29:36 GMT Organization: none Message-ID: <820952976snz@genesis.demon.co.uk> References: <DKDA7D.Kw7@midway.uchicago.edu> <j66Sx*FRe@yaps.rhein.de> <DKKHCH.L6r@midway.uchicago.edu> <4ccbdb$5v6@fg70.rz.uni-karlsruhe.de> <DKo8ns.8A9@midway.uchicago.edu> <DKp9L9.234@ukpsshp1.serigate.philips.nl> Reply-To: fred@genesis.demon.co.uk X-NNTP-Posting-Host: genesis.demon.co.uk X-Newsreader: Demon Internet Simple News v1.27 X-Mail2News-Path: genesis.demon.co.uk