Assembly Language for Beginners

(nextflipdebug2) #1

3.18. C++


R-------456

11, 12 has been inserted
root----123
L-------11
R-------12
R-------456


100, 1001 has been inserted
root----123
L-------12
L-------11
R-------100
R-------456
R-------1001


667, 1, 4, 7 has been inserted
root----12
L-------4
L-------1
R-------11
L-------7
R-------123
L-------100
R-------667
L-------456
R-------1001


3.18.5 Memory.


Sometimes you may hear from C++ programmers “allocate memory on stack” and/or “allocate memory
onheap”.


Allocating objecton stack:


void f()
{
...


Class o=Class(...);

...
};


Thememoryforobject(orstructure)isallocatedinstack,usingsimpleSPshift. Thememoryisdeallocated
upon function exit, or, more precisely, at the end ofscope—SPis returning to its state (same as at the
start of function) and destructor ofClassis called. In the same manner, memory for allocated structure
in C is deallocated upon function exit.


Allocating objectonheap:


void f1()
{
...


Class *o=new Class(...);

...
};


void f2()
{
...


delete o;

...
};

Free download pdf