Re: malloc vs new for POD types
From: Paul (paul_at_paul.com)
Date: 10/31/04
- Next message: Paul: "Re: malloc vs new for POD types"
- Previous message: Edi Weitz: "Re: C++ sucks for games"
- In reply to: Method Man: "Re: malloc vs new for POD types"
- Next in thread: Paul: "Re: malloc vs new for POD types"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 31 Oct 2004 08:04:14 -0500
"Method Man" <a@b.c> wrote in message
news:hHUgd.552$14.136@read1.cgocable.net...
>
> I don't see the problem with copying objects bit-by-bit. It's ok for
structs
> isn't it? Can someone shed some light?
>
"Method Man" <a@b.c> wrote in message > It's not quite what I was after. But
I found "[16.4] Can I use realloc() on
> pointers allocated via new?" interesting to read. Here's the partial
answer
> from the FAQ:
>
> I don't see the problem with copying objects bit-by-bit. It's ok for
structs
> isn't it? Can someone shed some light?
>
>
Read the rest of the FAQ. For example, what if the object is
reference-counted? You don't update the reference count if you blindly copy
the object by using realloc(). Some implementations use reference counted
std::string's. If you bypass the copy-assign operators, you will
undoubtedly render the string object(s) unstable.
In general, that's why there is such a thing as a user-defined copy
constructor and assignment operator. They are there for a purpose, and that
purpose is to do something important if the object is copied or assigned.
-Paul
- Next message: Paul: "Re: malloc vs new for POD types"
- Previous message: Edi Weitz: "Re: C++ sucks for games"
- In reply to: Method Man: "Re: malloc vs new for POD types"
- Next in thread: Paul: "Re: malloc vs new for POD types"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|