classes, pointers, vectors, and memory allocation

mosfets_at_gmail.com
Date: 02/06/05


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



Relevant Pages

  • Re: Memory management terminology
    ... We've ruled out a memory ... and let's assume that heap fragmentation is not the problem. ... While not directly a memory leak, ... it is indeed "private bytes" that we're measuring. ...
    (microsoft.public.vc.language)
  • Re: Tracking a memory leak.
    ... I know that TaskManager may not be the best place to see what is the true way to gauge memory usage and/or presense of memory leaks. ... You should take a look at the "CLR Memory performance" counters, notably the Gen0, 1, 2 and Large Object heap counters are of interest. ... What is shown in Taskman is the size of your process Working Set or the Private Bytes, the GC allocates and de-allocates object space from a Private Heap holding the above generational heaps, this Private Heap,w which is part of the Private Bytes and the Working Set, grows, by requesting new segments from the OS, whenever the Generational heap 0 is full and the GC needs more space to allocate objects from. ... The CLR "Memory Allocator" de-commits the pages that were previously occupied by object data, and returns the Segment to the OS when *all pages* from that segment are decommited. ...
    (microsoft.public.dotnet.languages.csharp)
  • investigating unmanaged memory
    ... into this memory and find out which objects comprise the native/unmanaged ... memory portion of the application private bytes? ... profiler only looks at managed heap. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: where do the extra bytes go while using Malloc ?
    ... In the case of heap, to keep track of a single chunk of memory it ... How does malloc/calloc then allocate the exact size of data as ...
    (comp.lang.c)
  • Re: MEMORY block
    ... >> which allocates x amount of memory, it should then get contigious memory ... > memory from the heap and freereturns it to the heap. ... If it is one big chunk, performance is a lot better, and I really mean a lot ...
    (comp.unix.solaris)