Object creation on the stack/heap?

Actually, neither statement says anything about heap or stack. The code Object o; creates one of the following, depending on its context: a local variable with automatic storage, a static variable at namespace or file scope, a member variable that designates the subobject of another object. This means that the storage location is determined by … Read more

Why not use pointers for everything in C++?

Yes, one is on the stack, the other on the heap. There are two important differences: First, the obvious, and less important one: Heap allocations are slow. Stack allocations are fast. Second, and much more important is RAII. Because the stack-allocated version is automatically cleaned up, it is useful. Its destructor is automatically called, which … Read more

Is a Java array of primitives stored in stack or heap?

As gurukulki said, it’s stored on the heap. However, your post suggested a misunderstanding probably due to some well-intentioned person propagating the myth that “primitives always live on the stack”. This is untrue. Local variables have their values on the stack, but not all primitive variables are local… For example, consider this: public class Foo … Read more

kernel stack and user space stack

What’s the difference between kernel stack and user stack ? In short, nothing – apart from using a different location in memory (and hence a different value for the stack pointer register), and usually different memory access protections. I.e. when executing in user mode, kernel memory (part of which is the kernel stack) will not … Read more

What is the function of the push / pop instructions used on registers in x86 assembly?

pushing a value (not necessarily stored in a register) means writing it to the stack. popping means restoring whatever is on top of the stack into a register. Those are basic instructions: push 0xdeadbeef ; push a value to the stack pop eax ; eax is now 0xdeadbeef ; swap contents of registers push eax … Read more