placement new + array +alignment

前端 未结 4 1148
鱼传尺愫
鱼传尺愫 2020-12-10 04:06
SomeObj* Buffer;
char* BufferPtr = MemoryManager::giveMeSomeBytes(resX*resY*sizeof(SomeObj));
Buffer = new(BufferPtr) SomeObj         


        
4条回答
  •  天命终不由人
    2020-12-10 04:37

    As others have said, this is due to your C++ implementation storing the size of the array at the start of the buffer you pass to array placement new.

    An easy fix for this is to simply assign your array pointer to the buffer, then loop over the array and use regular (non-array) placement new to construct each object in the buffer.

提交回复
热议问题