Understanding Storage Duration, Dynamic Memory, and Building a Custom Vector in C

Storage Duration Categories In C, objects have specific lifetimes determined by their storage duration. There are three primary types: Static Storage Duration: Variables declared outside functions or with static inside functions. They exist for the entire program execution. Automatic Storage Duration: Local variables (typically on the stack). ...

Posted on Sun, 09 Aug 2026 16:25:28 +0000 by jannoy

Dynamic Memory Management in C: malloc, calloc, realloc and Pitfalls

Motivation for Runtime Allocation Automatic variables and fixed-size arrays live on the stack and their sizes are frozen at compile time. When the required amount of data is not known until the program is running, the heap offers a flexible alternative. Core Allocation Routines All prototypes live in <stdlib.h>. malloc void *malloc(size_ ...

Posted on Sat, 01 Aug 2026 16:29:43 +0000 by junrey

C++ Dynamic Memory Management with new and delete

Memory Layout of a C/C++ Process Before diving into allocation APIs, it helps to know where objects live. int globalVal = 1; static int staticGlobalVal = 1; void demo() { static int staticVal = 1; int localVal = 1; int nums[10] = {1, 2, 3, 4}; char buf[] = "abcd"; const char* literal = "abcd"; int* p ...

Posted on Sat, 16 May 2026 12:08:13 +0000 by ESCForums.com