From 5210990963254891896
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,10e355266b6fd117
X-Google-Attributes: gidf78e5,public
X-Google-Thread: fc772,10e355266b6fd117
X-Google-Attributes: gidfc772,public
X-Google-ArrivalTime: 2002-05-28 19:52:11 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.uchicago.edu!newsfeed.cs.wisc.edu!nnxp1.twtelecom.net!209.98.3.200.MISMATCH!priapus.visi.com!news-out.visi.com!hermes.visi.com!feed.news.qwest.net!namche.sun.com!news2me.EBay.Sun.COM!engnews1.eng.sun.com!taumet!clamage
From: Attila Feher <Attila.Feher@lmf.ericsson.se>
Newsgroups: comp.std.c++,comp.lang.c++.moderated
Subject: Re: A humble attempt to suggest alignment support for C++
Date: 29 May 2002 02:42:07 GMT
Organization: Oy L M Ericsson Ab
Lines: 83
Approved: stephen.clamage@sun.com (comp.std.c++)
Message-ID: <3CF3B6F6.5DE49C64@lmf.ericsson.se>
References: <3CEA1A08.C6D95CC7@lmf.ericsson.se>
 <53e3f3b2.0205270557.bdd703d@posting.google.com>
NNTP-Posting-Host: taumet.eng.sun.com
X-NNTP-Posting-Host: netlab.cs.rpi.edu
X-Original-Date: Tue, 28 May 2002 19:57:26 +0300
X-Submission-Address: c++-submit@netlab.cs.rpi.edu
X-Auth: PGPMoose V1.1 PGP comp.lang.c++.moderated
	iQBVAwUAPPPxSUHMCo9UcraBAQGocAH/fGw9Igpa/RgZrsbkDb3IBatl/ftWqk6E
	N6kABryJQTd41I9hg1J3eFw9MCEo1IoLZs2ANyG2q+bNmAVgsYPOyw==
	=NUVV
X-Approved-For-Group: hsutter@acm.org comp.lang.c++.moderated
X-Scanned-By: MIMEDefang 2.3 (www dot roaringpenguin dot com slash mimedefang)
Content-Length: 3378
Originator: clamage@taumet
Xref: archiver1.google.com comp.std.c++:11646 comp.lang.c++.moderated:44097


McNepp wrote:
[SNIP]
> Yes, portable support for alignment is long overdue.
> But why not keep it as simple as possible?

I guess what I have suggested is simple.

> We want this declaration:
> 
> char buffer[ count * sizeof(T) ];
> 
> to be a suitably aligned buffer for any type T.

Nope.  I wan't it to be suitably aligned to the _specific_ type T used
there!  Not _any_, because this means wasting of memory!

> So what is really needed is just a simple specifier (e.g. "max_align")

> that does the trick:
> 
> char max_align buffer[ count * sizeof(T) ];

One point of my proposal was to avoid using maximum alignment
everywhere.

> Now we can safely cast this buffer to a T-array, using two 
> static_casts... which immediately triggers the question: Why not skip 
> the new keyword altogether and even get rid of one of the 
> static_casts? What about allowing this syntax:
> 
> void buffer[ count * sizeof(T) ];
> 
> This generic buffer can be safely cast (with one simple static_cast) 
> to any type T. No new keywords needed, simple and self-explanatory, 
> isn't it?

It is simple, but it isn't obvious (self explanatory) at all.  And what
if I have already (for some reason) the size given to me?  So the type T
will not even be mentioned in this line, unless there is a separate
aligment specification?

Also your proposal does not support if I need to align any arbitrary
pointer.  Like I have a buffer in shared memory and I would like to
place there an object, which needs alignment.  I have a pointer to the
first free byte.

So I guess why being simple is A OK with me, being ambiguously implicit
ends up being "too simple".  I believe that this aligment issue needs
two kind of support: an alignment specifier and an "aligment calculator"
taking a void * plus a length and returning void * to the first suitable
address, where type T can be constructed _or_ throws std::ollala if it
cannot be done within the given buffer size.  Or you can give "one past
end iterator" as well (instead of length), I guess it even would be
better.

When I say we need these two I mean that we need if we want to have a
complete solution and forget about the problem.  And of course: we might
need to allow user defined extension (that's the reason why for the
template syntax) of these two functions (well, I have no idea how could
we actually do sth for the aligment specifier part) so that people can
create their own special aligment requirements for their own special
types.  But I guess once we enter this zone, the implementation will
_always_ be platform specific, so we can leave it out as well - since
the whole idea was to remain platform independent.  And whoever needs
any more wonders can just use the platform specific address arithmetics
to create a good enough pointer.  Since these special cases of more
strict aligment requirements (I guess) can only come up if some special
HW requires it in low level code.

Attila



      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]




