classes, pointers, vectors, and memory allocation
mosfets_at_gmail.com
Date: 02/06/05
- Next message: Risto Lankinen: "Re: Self Assignment check in Copy ctor"
- Previous message: Jonathan Turkanis: "Re: [OT] Re: New Promotion, need advice from experience people who deal with this situation."
- Next in thread: niklasb_at_microsoft.com: "Re: classes, pointers, vectors, and memory allocation"
- Reply: niklasb_at_microsoft.com: "Re: classes, pointers, vectors, and memory allocation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 5 Feb 2005 23:37:02 -0800
Hi,
I'm having a little trouble figuring out the difference in terms of
memory allocation between:
class person_info;
class A {
private:
vector<person_info> list;
};
class B {
private:
vector<person_info*> list;
};
int func1() {
A* ptr1 = new A();
B* ptr2 = new B();
person_info info_stack;
person_info* info_heap = new person_info();
}
ptr1 and ptr2 will be dynamically allocated in the heap, but when I add
info_stack to ptr1's vector list, info_stack will be copied into the
heap??? Or will info_stack still reside in the stack? If it is added
into the heap, does A's memory get enlarged as a whole chunk? If there
is not enough space for the whole chunk, will A get copied into another
chunk in the heap big enough to fit it?
What happens when I exit func1 and info_stack gets destroyed, what will
happen to the info_stack I put into the vector in ptr1? Can I still
access it and keep using it?
When i add info_heap to ptr2's vector list, will the memory of B in the
heap be enlarged as a whole chunk?
Sorry for so many questions, but I've been really confused about this
for a while.
Thanks for any help, and for reading this!
John G
- Next message: Risto Lankinen: "Re: Self Assignment check in Copy ctor"
- Previous message: Jonathan Turkanis: "Re: [OT] Re: New Promotion, need advice from experience people who deal with this situation."
- Next in thread: niklasb_at_microsoft.com: "Re: classes, pointers, vectors, and memory allocation"
- Reply: niklasb_at_microsoft.com: "Re: classes, pointers, vectors, and memory allocation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|