Knowing when to use [ ] vs .at( ) in Qt to read vs write data to objects

Knowing when to use [ ] vs .at( ) in Qt to read vs write data to objects

In Qt c++, you can directly access members of an object, whether it’s a class or struct, by using the square brackets [ and ] after the name of the object. For example:

classObject[0].classMember

Using square brackets [ and ] on an object allows you to directly READ AND WRITE to the member. However, knowing the difference between WHEN to use it could help increase the performance of the data handling cycles. In order to directly access that member data, and to allow read AND write access, Qt has to create a new pointer to the object itself in memory to do so. And creating pointers costs a lot of memory. And if you’re dealing with hundreds of thousands of objects and their hundreds of members, then things can get sluggish. Continue reading “Knowing when to use [ ] vs .at( ) in Qt to read vs write data to objects”

3D Graphics Performance Optimization Techniques

Although the tips in the following link are only concerning DirectX9, it may still be useful in Qt:

https://msdn.microsoft.com/en-us/library/windows/desktop/bb147263(v=vs.85).aspx

Notably:

  • Only redraw to the image buffer when you need to
  • Use smaller textures
  • Draw objects from front to back
  • Constantly test your code’s performance
  • Use one large array/buffer of vertices
  • Draw only what needs to be drawn, so culling and z-ordering can only help more

The ideal is to get a higher framerate which is perceivably better experience for the user. For 2D graphics, 16 frames per second is satisfactory. But for 3D graphics, 30 frames per second seems to be tolerable, but 60 frames per second is the minimal. But if you’re just learning 3D graphics programming, don’t worry about frames per second, just worry about the geometry and math to make sure it is correct. Then you can optimize it when you’re confident you understand how it all works.