Skip to main content
added 123 characters in body
Source Link
Summer
  • 2.4k
  • 2
  • 16
  • 31

To address your concern about using new the answer is don't. Creating an object without new simply requires calling the constructor. You will then use RAII to manage the lifetime of your objects. There may come a day when you need objects to persist beyond their scope but you shouldn't today.

This:

Cell* mapCell = new Cell(Point(x, y, z));
_floorCellMatrix.addCell(x, y, mapCell);

Can be changed to:

_floorCellMatrix.addCell(x, y, Cell(Point(x, y, z)));

And any other new's can likely be similarly removed. The article you linked is about smart pointers which have mostly replaced the use of new and delete. It is an important subject. Read up on it.

Your performance problem is either in your Cell constructor or the vectormatrix addCell() method.

  • Dont name anything with a leading underscore _. Many uses of the leading underscore are reserved and the rules are complicated. If you choose to use them anyway be thorough about how it works but it is common to simply avoid them and save the headache.

  • Don't declare empty constructors and destructors. Especially since you don't want to create any Cells without the use of parameters.

  • You are using pointers, not references, to your window and renderer, however that should not deliver a significant performance hit.

  • I would still argue that the Cell class should know nothing about how it's drawn and that the renderer and window should iterate over the vectormatrix and handle that. The vectormatrix shouldnt do that either. There is a concept called SRP or Single Responsibility Principle that suggests these classes need to know about their jobs and thats it.

  • Lastly you are creating your keyTileMap every single time you make Cell. That has to be your performance hit.

To address your concern about using new the answer is don't. Creating an object without new simply requires calling the constructor. You will then use RAII to manage the lifetime of your objects. There may come a day when you need objects to persist beyond their scope but you shouldn't today.

This:

Cell* mapCell = new Cell(Point(x, y, z));
_floorCellMatrix.addCell(x, y, mapCell);

Can be changed to:

_floorCellMatrix.addCell(x, y, Cell(Point(x, y, z)));

And any other new's can likely be similarly removed. The article you linked is about smart pointers which have mostly replaced the use of new and delete. It is an important subject. Read up on it.

Your performance problem is either in your Cell constructor or the vectormatrix addCell() method.

  • Dont name anything with a leading underscore _. Many uses of the leading underscore are reserved and the rules are complicated. If you choose to use them anyway be thorough about how it works but it is common to simply avoid them and save the headache.

  • Don't declare empty constructors and destructors. Especially since you don't want to create any Cells without the use of parameters.

  • You are using pointers, not references, to your window and renderer, however that should not deliver a significant performance hit.

  • I would still argue that the Cell class should know nothing about how it's drawn and that the renderer and window should iterate over the vectormatrix and handle that. The vectormatrix shouldnt do that either. There is a concept called SRP or Single Responsibility Principle that suggests these classes need to know about their jobs and thats it.

To address your concern about using new the answer is don't. Creating an object without new simply requires calling the constructor. You will then use RAII to manage the lifetime of your objects. There may come a day when you need objects to persist beyond their scope but you shouldn't today.

This:

Cell* mapCell = new Cell(Point(x, y, z));
_floorCellMatrix.addCell(x, y, mapCell);

Can be changed to:

_floorCellMatrix.addCell(x, y, Cell(Point(x, y, z)));

And any other new's can likely be similarly removed. The article you linked is about smart pointers which have mostly replaced the use of new and delete. It is an important subject. Read up on it.

Your performance problem is either in your Cell constructor or the vectormatrix addCell() method.

  • Dont name anything with a leading underscore _. Many uses of the leading underscore are reserved and the rules are complicated. If you choose to use them anyway be thorough about how it works but it is common to simply avoid them and save the headache.

  • Don't declare empty constructors and destructors. Especially since you don't want to create any Cells without the use of parameters.

  • You are using pointers, not references, to your window and renderer, however that should not deliver a significant performance hit.

  • I would still argue that the Cell class should know nothing about how it's drawn and that the renderer and window should iterate over the vectormatrix and handle that. The vectormatrix shouldnt do that either. There is a concept called SRP or Single Responsibility Principle that suggests these classes need to know about their jobs and thats it.

  • Lastly you are creating your keyTileMap every single time you make Cell. That has to be your performance hit.

deleted 23 characters in body
Source Link
Summer
  • 2.4k
  • 2
  • 16
  • 31

To address your concern about using new the answer is don't. Creating an object without new simply requires calling the constructor. You will then use RAII to manage the lifetime of your objects. There may come a day when you need objects to persist beyond their scope but you shouldn't today.

This:

Cell* mapCell = new Cell(Point(x, y, z));
_floorCellMatrix.addCell(x, y, mapCell);

Can be changed to:

_floorCellMatrix.addCell(x, y, Cell(Point(x, y, z)));

And any other new's can likely be similarly removed. The article you linked is about smart pointers which have mostly replaced the use of new and delete. It is an important subject. Read up on it.

Your performance problem is likelyeither in your Cell constructor. It seems or the most likely culprit so thats where I will digvectormatrix addCell() method.

  • Dont name anything with a leading underscore _. Many uses of the leading underscore are reserved and the rules are complicated. If you choose to use them anyway be thorough about how it works but it is common to simply avoid them and save the headache.

  • Don't declare empty constructors and destructors. Especially since you don't want to create any Cells without the use of parameters.

  • You are using pointers, not references, to your window and renderer, however that should not deliver a significant performance hit.

  • I would still argue that the Cell class should know nothing about how it's drawn and that the renderer and window should iterate over the vectormatrix and handle that. The vectormatrix shouldnt do that either. There is a concept called SRP or Single Responsibility Principle that suggests these classes need to know about their jobs and thats it.

To address your concern about using new the answer is don't. Creating an object without new simply requires calling the constructor. You will then use RAII to manage the lifetime of your objects. There may come a day when you need objects to persist beyond their scope but you shouldn't today.

This:

Cell* mapCell = new Cell(Point(x, y, z));
_floorCellMatrix.addCell(x, y, mapCell);

Can be changed to:

_floorCellMatrix.addCell(x, y, Cell(Point(x, y, z)));

And any other new's can likely be similarly removed. The article you linked is about smart pointers which have mostly replaced the use of new and delete. It is an important subject. Read up on it.

Your performance problem is likely in your Cell constructor. It seems the most likely culprit so thats where I will dig.

  • Dont name anything with a leading underscore _. Many uses of the leading underscore are reserved and the rules are complicated. If you choose to use them anyway be thorough about how it works but it is common to simply avoid them and save the headache.

  • Don't declare empty constructors and destructors. Especially since you don't want to create any Cells without the use of parameters.

  • You are using pointers, not references, to your window and renderer, however that should not deliver a significant performance hit.

  • I would still argue that the Cell class should know nothing about how it's drawn and that the renderer and window should iterate over the vectormatrix and handle that. The vectormatrix shouldnt do that either. There is a concept called SRP or Single Responsibility Principle that suggests these classes need to know about their jobs and thats it.

To address your concern about using new the answer is don't. Creating an object without new simply requires calling the constructor. You will then use RAII to manage the lifetime of your objects. There may come a day when you need objects to persist beyond their scope but you shouldn't today.

This:

Cell* mapCell = new Cell(Point(x, y, z));
_floorCellMatrix.addCell(x, y, mapCell);

Can be changed to:

_floorCellMatrix.addCell(x, y, Cell(Point(x, y, z)));

And any other new's can likely be similarly removed. The article you linked is about smart pointers which have mostly replaced the use of new and delete. It is an important subject. Read up on it.

Your performance problem is either in your Cell constructor or the vectormatrix addCell() method.

  • Dont name anything with a leading underscore _. Many uses of the leading underscore are reserved and the rules are complicated. If you choose to use them anyway be thorough about how it works but it is common to simply avoid them and save the headache.

  • Don't declare empty constructors and destructors. Especially since you don't want to create any Cells without the use of parameters.

  • You are using pointers, not references, to your window and renderer, however that should not deliver a significant performance hit.

  • I would still argue that the Cell class should know nothing about how it's drawn and that the renderer and window should iterate over the vectormatrix and handle that. The vectormatrix shouldnt do that either. There is a concept called SRP or Single Responsibility Principle that suggests these classes need to know about their jobs and thats it.

added 429 characters in body
Source Link
Summer
  • 2.4k
  • 2
  • 16
  • 31

To address your concern about using new the answer is don't. Creating an object without new simply requires calling the constructor. You will then use RAII to manage the lifetime of your objects. There may come a day when you need objects to persist beyond their scope but you shouldn't today.

This:

Cell* mapCell = new Cell(Point(x, y, z));
_floorCellMatrix.addCell(x, y, mapCell);

Can be changed to:

_floorCellMatrix.addCell(x, y, Cell(Point(x, y, z)));

And any other new's can likely be similarly removed. The article you linked is about smart pointers which have mostly replaced the use of new and delete. It is an important subject. Read up on it.

Your performance problem is likely in your Cell constructor. It seems the most likely culprit so thats where I will dig.

If you are going to use the window and renderer they should be maintained as references. However I would strongly argue that the Cell class should know nothing about how it's drawn and that the renderer and window should iterate over the vectormatrix and handle that

Lastly dont name anything with a leading underscore _. Many uses of the leading underscore are reserved and the rules are complicated. If you choose to use them anyway be thorough about how it works but it is common to simply avoid them and save the headache.

  • Dont name anything with a leading underscore _. Many uses of the leading underscore are reserved and the rules are complicated. If you choose to use them anyway be thorough about how it works but it is common to simply avoid them and save the headache.

  • Don't declare empty constructors and destructors. Especially since you don't want to create any Cells without the use of parameters.

  • You are using pointers, not references, to your window and renderer, however that should not deliver a significant performance hit.

  • I would still argue that the Cell class should know nothing about how it's drawn and that the renderer and window should iterate over the vectormatrix and handle that. The vectormatrix shouldnt do that either. There is a concept called SRP or Single Responsibility Principle that suggests these classes need to know about their jobs and thats it.

To address your concern about using new the answer is don't. Creating an object without new simply requires calling the constructor. You will then use RAII to manage the lifetime of your objects. There may come a day when you need objects to persist beyond their scope but you shouldn't today.

This:

Cell* mapCell = new Cell(Point(x, y, z));
_floorCellMatrix.addCell(x, y, mapCell);

Can be changed to:

_floorCellMatrix.addCell(x, y, Cell(Point(x, y, z)));

And any other new's can likely be similarly removed. The article you linked is about smart pointers which have mostly replaced the use of new and delete. It is an important subject. Read up on it.

Your performance problem is likely in your Cell constructor. It seems the most likely culprit so thats where I will dig.

If you are going to use the window and renderer they should be maintained as references. However I would strongly argue that the Cell class should know nothing about how it's drawn and that the renderer and window should iterate over the vectormatrix and handle that

Lastly dont name anything with a leading underscore _. Many uses of the leading underscore are reserved and the rules are complicated. If you choose to use them anyway be thorough about how it works but it is common to simply avoid them and save the headache.

To address your concern about using new the answer is don't. Creating an object without new simply requires calling the constructor. You will then use RAII to manage the lifetime of your objects. There may come a day when you need objects to persist beyond their scope but you shouldn't today.

This:

Cell* mapCell = new Cell(Point(x, y, z));
_floorCellMatrix.addCell(x, y, mapCell);

Can be changed to:

_floorCellMatrix.addCell(x, y, Cell(Point(x, y, z)));

And any other new's can likely be similarly removed. The article you linked is about smart pointers which have mostly replaced the use of new and delete. It is an important subject. Read up on it.

Your performance problem is likely in your Cell constructor. It seems the most likely culprit so thats where I will dig.

  • Dont name anything with a leading underscore _. Many uses of the leading underscore are reserved and the rules are complicated. If you choose to use them anyway be thorough about how it works but it is common to simply avoid them and save the headache.

  • Don't declare empty constructors and destructors. Especially since you don't want to create any Cells without the use of parameters.

  • You are using pointers, not references, to your window and renderer, however that should not deliver a significant performance hit.

  • I would still argue that the Cell class should know nothing about how it's drawn and that the renderer and window should iterate over the vectormatrix and handle that. The vectormatrix shouldnt do that either. There is a concept called SRP or Single Responsibility Principle that suggests these classes need to know about their jobs and thats it.

deleted 427 characters in body
Source Link
Summer
  • 2.4k
  • 2
  • 16
  • 31
Loading
added 538 characters in body
Source Link
Summer
  • 2.4k
  • 2
  • 16
  • 31
Loading
Source Link
Summer
  • 2.4k
  • 2
  • 16
  • 31
Loading