Creating “classes” in C, on the stack vs the heap?

There are several reasons for this. Using “opaque” pointers Lack of destructors Embedded systems (stack overflow problem) Containers Inertia “Laziness” Let’s discuss them briefly. For opaque pointers, it enables you to do something like: struct CClass_; typedef struct CClass_ CClass; // the rest as in your example So, the user doesn’t see the definition of … Read more

Why are the terms “automatic” and “dynamic” preferred over the terms “stack” and “heap” in C++ memory management?

Automatic tells me something about the lifetime of an object: specifically that it is bound automatically to the enclosing scope, and will be destroyed automatically when that scope exits. Dynamic tells me that the lifetime of an object is not controlled automatically by the compiler, but is under my direct control. Stack is an overloaded … Read more

Size of stack and heap memory [duplicate]

“Stack is created in the top-level-address and the heap at the low-level-address” Please elobarate this This is a myth. It may have a basis in historical truth. It might sometimes resonate with things you see in real life. But it is not literally true. It’s easy enough to explore, though: #include <stdlib.h> #include <stdio.h> void … Read more