Re: [C++] Vectors & Dynamic allocation
From: Robert W Hand (rwhand_at_NOSPAMoperamail.com)
Date: 04/30/04
- Next message: B. v Ingen Schenau: "Re: C++ Conversion functions for pointers"
- Previous message: B. v Ingen Schenau: "Re: temporary file in C++"
- In reply to: Anand Hariharan: "Re: [C++] Vectors & Dynamic allocation"
- Next in thread: Francis Glassborow: "Re: [C++] Vectors & Dynamic allocation"
- Reply: Francis Glassborow: "Re: [C++] Vectors & Dynamic allocation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 30 Apr 2004 05:15:54 -0400
On 29 Apr 2004 16:59:30 -0700, desh_bakth@yahoo.com (Anand Hariharan)
wrote:
>Robert W Hand <rwhand@NOSPAMoperamail.com> wrote in message news:<iovt80phf4fkdq2dtikc0e8e82abju544n@4ax.com>...
>
>> I agree that complexity requirements for
>> std::vector::erase clearly prohibit deallocation of the elements.
>>
>
>Am unsure what the complexity requirements might have to do with the
>deallocation of elements.
In the section of the Standard devoted to std::vector<T>::erase, there
is a paragraph labeled "Complexity". It states that the destructor of
T is called the number of times equal to the number of elements
erased, but the assignment operator for T is called the number of
times equal to the number of elements after the erased elements.
There is no provision for deallocation. Furthermore, since iterators
before the erasure remain valid, an allocation/deallocation step seems
impossible. Deallocation/allocation would invalidate all the
iterators.
>AFAICS, getting vector's erase to check if the elements need
>deallocation etc mimics Garbage collection - a price a developer might
>not be willing to pay. However, even if this were to be included, its
>complexity would still be O(n), isn't it?
The complexity of erase depends upon the type of container. For
vector, it seems to me that we are mixing different lengths of two
different operations. Erasing the last element of a vector should be
different than erasing the first element. In the case of the last
element, only one element is erased and none copied. In the case of
the first element, one element is erased and size()-1 are copied.
Doesn't seem to fit into a neat O(0) complexity. Perhaps someone has
a different idea?
-- Best wishes, Bob
- Next message: B. v Ingen Schenau: "Re: C++ Conversion functions for pointers"
- Previous message: B. v Ingen Schenau: "Re: temporary file in C++"
- In reply to: Anand Hariharan: "Re: [C++] Vectors & Dynamic allocation"
- Next in thread: Francis Glassborow: "Re: [C++] Vectors & Dynamic allocation"
- Reply: Francis Glassborow: "Re: [C++] Vectors & Dynamic allocation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|