Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: More controll over sf::VertexArray's vector  (Read 2842 times)

0 Members and 1 Guest are viewing this topic.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
More controll over sf::VertexArray's vector
« on: September 16, 2012, 05:55:35 pm »
If we know how many vertices we will load we could reserve() space instead of relying on appends(push_backs) that will :
1. reallocate few times
2. possibly reserve more memory than they need
How bad these two will be depends on implementation of the vector.
The un-solution is using resize but it still feels like there are unnecessary restrictions.

Possible changes I think of:
- reserve(vector's reserve) and/or trim(Scott Meyer's ranged swap on the underlying vector) methods
- method to return non-const pointer/reference to underlying vector since it seems nothing in the vertex array code will break no matter what is done to the vector(except deletion, but really, delete &something; can be done on anything and there are more dangerous things in sfml already).
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: More controll over sf::VertexArray's vector
« Reply #1 on: September 16, 2012, 07:27:25 pm »
sf::VertexArray is just a simple wrapper for people who could be scared to use a std::vector. But if you want more power, use it directly.
Laurent Gomila - SFML developer

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: More controll over sf::VertexArray's vector
« Reply #2 on: September 16, 2012, 07:38:56 pm »
I am :P but I wanted to point this out since in my case the numbers were quite scary.
Back to C++ gamedev with SFML in May 2023