Search code examples
c++compiler-construction

Do compiler creates an overhead for static (compile-time) arrays?


I know that when you allocate an array with

int* arr = new int[n];

the compile creates an overhead to know how many there elements to deallocate. But does it creates an overhead to static arrays

int arr[4];

I think that the answer is no because you cannot delete[] such array, but I need to know for sure. Thanks!


Solution

  • You are right. No additional storage is required. The deallocation happens automatically in case of variables with automatic storage duration. The compiler has all the information it needs at compile-time to know when and how much memory to deallocate