stack allocation
Memory allocated automatically for local variables;
very fast, lifetime tied to scope.
heap allocation
Memory allocated dynamically (new/malloc);
slower, requires manual/free or smart pointers.
memory pool
Pre-allocated block of memory for fast allocation/deallocation
memory leak
Memory allocated but never freed
Dangling Pointer
Pointer to freed memory;
unsafe, causes undefined behavior.
RAII
(Resource Acquisition Is Initialization)
Manage resources via object lifetime;
ensures cleanup.
Copy vs Move
Avoid unnecessary deep copies; use move semantics to transfer ownership efficiently.
Smart Pointers
(unique_ptr, shared_ptr, weak_ptr)
manage heap memory safely and prevent leaks.
Cache Locality
Accessing contiguous memory improves CPU cache usage;
vector > deque > list.
Spatial Locality
Accessing memory addresses near each other; improves cache hits
Temporal Locality
Re-accessing recently used memory; improves cache reuse
Contiguous Storage
Using structures like vector for sequential memory;
improves cache efficiency.
Memory Contention
Multiple threads accessing shared memory;
can cause stalls.
Time Complexity Awareness
O(1), O(log n), O(n) costs for data structures and operations.
Hot / Cold Data Separation
Separate frequently accessed vs rarely accessed data to improve cache hits.