From -7620941361567179521
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 08:52:11 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed.news.qwest.net!namche.sun.com!news2me.EBay.Sun.COM!engnews1.eng.sun.com!taumet!clamage
From: gneppert@web.de (McNepp)
Newsgroups: comp.std.c++,comp.lang.c++.moderated
Subject: Re: A humble attempt to suggest alignment support for C++
Date: 28 May 2002 15:47:45 GMT
Organization: http://groups.google.com/
Lines: 56
Approved: stephen.clamage@sun.com (comp.std.c++)
Message-ID: <53e3f3b2.0205270557.bdd703d@posting.google.com>
References: <3CEA1A08.C6D95CC7@lmf.ericsson.se>
NNTP-Posting-Host: taumet.eng.sun.com
X-NNTP-Posting-Host: netlab.cs.rpi.edu
X-Original-Date: 27 May 2002 06:57:01 -0700
X-Submission-Address: c++-submit@netlab.cs.rpi.edu
X-Auth: PGPMoose V1.1 PGP comp.lang.c++.moderated
	iQBVAwUAPPLweUHMCo9UcraBAQEpPQH/YXcTETmekAiSygarEc8dWgWkWuX5KrQU
	xIhZsxE738qFVa7x/oppNk1/m1rlZSJ5lPojoOvZqLIbp6BwyvdtQg==
	=gQTF
X-Approved-For-Group: jep@[151.161.11.6] comp.lang.c++.moderated
X-Scanned-By: MIMEDefang 2.3 (www dot roaringpenguin dot com slash mimedefang)
Content-Length: 1789
X-Status: $$$$
X-UID: 0000000001
Originator: clamage@taumet
Xref: archiver1.google.com comp.std.c++:11602 comp.lang.c++.moderated:44057


Attila Feher <Attila.Feher@lmf.ericsson.se> wrote in message news:<3CEA1A08.C6D95CC7@lmf.ericsson.se>...
> 
> 
> Motto:
> ------
> 
> Dynamic memory allocation is expensive.  To pay for it, just to get
> right alignment is silly.
> 
> 
> Motivation:
> -----------
> 
> C++ programmers many times face the issue of being able to create fixed
> capacity, dynamic sized sequential containers.  Right now, with current
> language features such a container can only be implemented using dynamic
> memory allocation, like vector.  But in many cases, such an allocation
> is an overkill.
> 

Yes, portable support for alignment is long overdue.
But why not keep it as simple as possible? 
We want this declaration:

char buffer[ count * sizeof(T) ];

to be a suitably aligned buffer for any type T. 
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) ];

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?



      [ 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                       ]




