From -7516971224671550333
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,839fa42e97baea86
X-Google-Attributes: gidf78e5,public
From: Hyman Rosen <hymie@prolifics.com>
Subject: Re: Placement new[] Compiler Depenent?
Date: 1998/11/20
Message-ID: <36535E69.CB09EC8B@prolifics.com>#1/1
X-Deja-AN: 413780638
Content-Transfer-Encoding: 7bit
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
References: <eDcSHHgdulIC-pn2-e3Hcgbrpl1Vl@eir.stiscan.com> <72v90t$9uq$1@engnews2.Eng.Sun.COM>
X-Original-Date: Wed, 18 Nov 1998 18:55:21 -0500
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: news@news.unimelb.edu.au
X-Trace: izvestia.its.unimelb.edu.au 911544604 20643 128.250.29.16 (20 Nov 1998 06:50:04 GMT)
Organization: Prolifics
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUANlURBuEDnX0m9pzZAQEpbQF/bi4zUBr9AB683DF4v1XJbr/X96v+h+gh El1fyt+/s/Kt1nIbAEKMwej9Jm2tQEgI =32kU
Mime-Version: 1.0
NNTP-Posting-Date: 20 Nov 1998 06:50:04 GMT
Newsgroups: comp.std.c++

Steve Clamage wrote:
> The added overhead must be an integral multiple of the worst-case
> alignment for any object that fits in requested size. Unfortunately,
> there is no standard way to find out what that alignment is, and
> no way to find out what integral multiple the compiler uses. (At
> least, not from inside the program using portable code. The compiler
> documentation might tell you, but of course the value can differ
> among implementations.)

Really? How about this?

struct sizer { };
void *operator new[](size_t b, const sizer &) { throw b; }

template<typename T>
size_t
size(size_t n)
{
	sizer s;
	try {
		new(s) T[n];
	} catch (size_t b) {
		return b;
	}
}
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]



