Finding size of dynamically allocated array

前端 未结 7 619
礼貌的吻别
礼貌的吻别 2020-12-10 11:08

Why is it not possible to get the length of a buffer allocated in this fashion.

AType * pArr = new AType[nVariable];

When the same array is

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-10 11:41

    The delete operator doesn't need to know the size to free the allocated memory, just like the free system call doesn't. This is because that problem is left to the operating system and not the compilers runtime system.

提交回复
热议问题