Skip to content

Latest commit

 

History

History
35 lines (28 loc) · 881 Bytes

memory_management_heap_allocation.md

File metadata and controls

35 lines (28 loc) · 881 Bytes

Heap allocation

Heap allocation consists of a few steps:

  • pointer allocation on a stack
  • sizeof(T) bytes allocation on a heap
  • T’s constructor call on allocated memory
  • the memory address assignment to the pointer
  • manual deallocation using delete operator
void heap()
{
    int *p = new int(100);
    delete p;
}

void heap()
{
    int *p;
    p = (int*)malloc(sizeof(int));
    *p = 100;
    free(p);
}