I'm working as java programmer and just now starting to learn c++ and irrlicht (want to create games as a hobby ;) ).
I am completely confused by stack vs heap issue.
What is the advantage of using heap? Isn't it MUCH faster and more efficient to create variales on stack and pass them by reference.
What I mean is:
Object obj = new Object();
I am also confused by memory managment in c++. When stack object is freed is there a memory "hall" in stack.
Generally in C++ if you want by reference passing of variables you define this in the function header not in it's use.
void functionByReference(const Object& obj); void functionByPointer(const Object* obj); //In compiled code(asm) there is no difference between this call and the one above it, the compiler does see this differently though. void functionByValue(const Object obj); //Both are called as follows Object object; functionByReference(object); //This call is faster then the one below it functionByValue(object); functionByPointer(&object); //You have to use the address operator here because the function is expecting a pointer to an object
Usually you only feed a function a "&<variable>" when you only have a stack value and the function wants a object that's passed by pointer. Even when the variable is an output parameter this is expressed in the function header and not in it's use.