0

i have trying to construct array of array for placement new.

i searching internet only manage to found construct an array using placement new. But what if i want array of array instead?

i not sure how to construct the inner array.

memory manager constructor already allocate buffer with large size

memory manager destructor have delete buff

Node operator new overload already implement

This my code

map_size_x = terrain->get_map_width();
map_size_y = terrain->get_map_height();

grid_map =  new Node *[map_size_x];

for (int i = 0; i < map_size_x; ++i)
{
    //grid_map[i] = new Node[map_size_y];
    grid_map[i] = new( buf + i * sizeof(Node)) Node;

}

buf is char * already allocated big size of memory in somewhere other class like memory manager and should be enough to fit in sizeof Node * width and height.

There is new operator overload implemented in Node class which is

  void *AStarPather::Node::operator new(std::size_t size, void* buffer)
  {
     return buffer;
  }

the result seem failed to allocate and program stuck, but no crash. i am using visual studio 2017

NMT
  • 55
  • 2
  • 9
  • Your overload is useless, since you cannot overload *placement `new`*. It is not used there. – Fureeish Jun 12 '19 at 09:34
  • how should i implement? – NMT Jun 12 '19 at 23:29
  • I'd recommend to create a class with automatic array of contiguous elements, overload `operator []` to return a proxy object and then overload `operator []` on that object to allow for intuitive indexing. You may then simply allocate it dynamically, if it's your desire. – Fureeish Jun 12 '19 at 23:34

0 Answers0