Finding size of dynamically allocated array

前端 未结 7 623
礼貌的吻别
礼貌的吻别 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:43

    There is no portable way in C++ to get the size of a dynamically allocated array from the raw pointer.

    Under MSVC and WIN32 you can get the size of the allocated block with the _msize(void*) function.

    see https://msdn.microsoft.com/en-us/library/z2s077bc.aspx for further details.

提交回复
热议问题