new [], delete [] complexity

后端 未结 4 1394
眼角桃花
眼角桃花 2021-02-07 10:23

I already know that the new[] operator first allocates memory and then calls the constructor for each element and that the delete[] operator first call

4条回答
  •  迷失自我
    2021-02-07 10:45

    MyClass *p = static_cast (::operator new (sizeof(MyClass[N])));
    

    Allocates memory for N objects and does not construct them. In that way the complexity will be the same as malloc(). It will be obviously faster, then allocating and constructing objects of complex class.

提交回复
热议问题