Re: Slightly OT: Compilation question
On Jun 16, 11:00 pm, Paul Hsieh <websn...@gmail.com> wrote:
On Jun 16, 12:48 pm, "Bo Persson" <b...@gmb.dk> wrote:
Paul Hsieh wrote:
On Jun 13, 8:15 pm, Keith Thompson <ks...@mib.org> wrote:
Paul Hsieh <websn...@gmail.com> writes:
It also
forces you to be more exact in function declarations. This I
found to be the biggest actual source code impact, as it
basically forces you to cast all mallocs.
Right (but it's usually better practice to use new and delete in
C++ anyway, or some STL type that manages memory for you).
C++ is built on the RAII principle. Using new and delete invoke
constructors which you might not want to happen. Furthermore, its
easy to show that STL's vector templates have either ridiculously
bad performance in comparison to hand managed realloc()'s precisely
because of the RAII overhead or else compromise your design to the
point that you might as well use realloc().
Constructors are invoked for types that have constructors. How do you
do that with realloc?
You don't. That's precisely the point I am trying to make.
In other words, you write code that doesn't work. Or you
reimplement all of std::vector yourself.
I.e., its not surprising that malloc/free has not been and
will not be deprecated in the C++.
Yes. They're there for the cases where you have to interface
with C code.
Is it?
Well, why don't you try and see what the reaction amongst real
world programmers or compiler vendors is? More seriously,
take a survey, look at real code and find out for yourself.
The reaction is that nobody uses malloc or free except when they
have to interface with legacy software.
Often C++'s power can be used to wrap "unsafe/gross" calls to
malloc and realloc anyways. I think that sort of flexibility
was intentional anyways to make sure someone couldn't complain
about capabilities taken away by C++. This is exactly what is
done in Bstrlib, and I wouldn't be surprised if many STL's use
realloc in the guts of their std::string class. It would be a
little hard to take away malloc/ realloc in view of this.
Why don't you actually find out what is going on, instead of
just speculating about it. The standard requires that all
allocations in the STL which use a default allocator go through
operator new(). And at least the implementations I have access
to (Sun CC, g++ and VC++) do.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34