new [], delete [] complexity

后端 未结 4 1397
眼角桃花
眼角桃花 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:42

    But if I have a class, for which I have not defined any constructor/destructor, will the complexity still be O(n), or will it be just O(1)?

    The members themselves might still have destructors. In short, for PODs, delete[] will be O(1).

提交回复
热议问题