[英]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但它是否会造成 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.我认为答案是否定的,因为你不能 delete[] 这样的数组,但我需要确定。 Thanks!谢谢!
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编译器在编译时拥有它需要的所有信息,以了解何时以及释放多少 memory
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.