Re: Vector and derived classes objects
From: ma740988 (ma740988_at_pegasus.cc.ucf.edu)
Date: 11/09/04
- Next message: Cy Edmunds: "Re: Arguments *Against* Exception Use"
- Previous message: andre dajd: "Re: Derived methods hiding inherited methods"
- In reply to: Victor Bazarov: "Re: Vector and derived classes objects"
- Next in thread: Karl Heinz Buchegger: "Re: Vector and derived classes objects"
- Reply: Karl Heinz Buchegger: "Re: Vector and derived classes objects"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 8 Nov 2004 16:12:54 -0800
Victor Bazarov <v.Abazarov@comAcast.net> wrote in message news:<aiMjd.8329$Ae.4337@newsread1.dllstx09.us.to.verio.net>...
> ma740988 wrote:
> > [...]
> > Since I am using just vector of pointers, the copy-ctor or assign-op
> > wont be called for the objects the pointer points to, hence I dont see
> > any way an exception can be thrown there with my push_back.
>
> Huh? push_back beyond the capacity of the vector _requires_ that the
> storage for that vector is grown. That means reallocation. That also
> means the original storage has to stay around until all the copying
> has competed. If your vector occupies at least half the memory that
> your process is allowed to have, there is no way in hell push_back can
> succeed without throwing to tell you that you've run out of memory.
[...]
Victor, appreaciate your patience but this reminds me of a course in
pertubation techniques where it took me 3 texts and days later before
I saw the light hence bear with me once more. I'm not arguing a throw
of bad_alloc, I understand. So now consider:
class X
{
std::string kdx;
public:
X() { }
};
int main()
{
X *ptr_x = new X();
std::size_t Jdx = sizeof (ptr_x);
std::cout << Jdx << std::endl;
std:vector<X*> my_vec;
my_vec.push_back(ptr_x);
std::cout << my_vec.size() << std::endl;
std::cout << my_vec.capacity() << std::endl;
delete ptr_x;
}
The output
4
1
1
on my platform. Now my_vec is a single byte. That said, I envision
it would require for me then to store a 'slew' of pointers (beyond the
capacity of the vectory - whatever number that is) to my_vec for me to
run out of memory. Correct?
- Next message: Cy Edmunds: "Re: Arguments *Against* Exception Use"
- Previous message: andre dajd: "Re: Derived methods hiding inherited methods"
- In reply to: Victor Bazarov: "Re: Vector and derived classes objects"
- Next in thread: Karl Heinz Buchegger: "Re: Vector and derived classes objects"
- Reply: Karl Heinz Buchegger: "Re: Vector and derived classes objects"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|