pool allocator changes and delete[] void*

Gawain Bolton gp.bolton@computer.org
Mon Dec 29 20:53:00 GMT 2003


----- Original Message ----- 
From: "Gabriel Dos Reis" <gdr@integrable-solutions.net>
To: "Gawain Bolton" <gp.bolton@computer.org>
Cc: "Paolo Carlini" <pcarlini@unitus.it>; "Paolo Carlini"
<pcarlini@suse.de>; "Gerald Pfeifer" <gerald@pfeifer.com>; "Benjamin Kosnik"
<bkoz@redhat.com>; <libstdc++@gcc.gnu.org>
Sent: Saturday, December 27, 2003 5:57 PM
Subject: Re: pool allocator changes and delete[] void*


> "Gawain Bolton" <gp.bolton@computer.org> writes:
>
> | I'm not understanding something here.  Why replace "new char[n]" with
> | "static_cast<char *>(::operator new(n))"?  It seems to me this is less
> | readable, less obvious and therefore less maintainable.
>
> What is less maintainable about?
>
> | What's the justification for such obfuscation?
>
> I have exactly the opposite view:  The previous was incorrect and
> obscure.

Incorrect I can now understand, would be nicer without the casting to char *
though :-)

> | It's not clear to me that operator
> | new(size_t) and operator delete(void *) are inverse functions.
>
> They are.  See 3.7.2 and 3.7.3

Ok, thanks.  One thing that seems incorrect to me is that the
__pool_alloc<__threads, __inst>::_S_chunk_alloc(size_t __n, int& __nobjs)
function in pool_allocator.h assumes that a NULL pointer is returned if the
new fails.  This does not strike me as being correct, since the
std::bad_alloc exception is thrown by operator new(std::size_t) if it fails
to allocate memory.


Gawain




More information about the Libstdc++ mailing list