|
Boost Users : |
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2006-07-10 10:53:27
On Mon, July 10, 2006 16:00, bringiton bringiton wrote:
>>>just look at the include files:
>
> i looked at the header, but got a little confused.
> i don't see how you can call a destruct of a a memory space that still
> exists. ie a C version of a vector.
>
> shared_ptr<int> list[1024];
> int n = 0;
>
> // add an item
> shared_ptr<int> newItem(new int(1));
> list[n++] = newItem;
>
> // remove the tail item
> n--;
> // destructor never called
>
> is it possible to call a destructor of an object that exists?
> what then happens then the object goes out of scope? the destructor will be
> called twice.
You can call the destructor directly.
To better understand why vector implementation does it, read about the "placement new"
operator. Some free source to start with is InformIt's C++ Reference Guide (Memory Management):
http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=28&rl=1
In this section is also an article (a small one) about Placement New operator:
http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=38&rl=1
And tips and techniques section describes it in a more detailed manner:
http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=160&rl=1
This section also has some links to other articles.
With Kind Regards,
Ovanes Markarian
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net