Jump to content

  • Log In with Google      Sign In   
  • Create Account


AnthonyB

Member Since 16 May 2009
Offline Last Active Jun 19 2012 04:41 PM

Topics I've Started

vector reallocation

24 March 2012 - 07:18 PM

Out of curiosity, I've been looking into how std::vector works in detail. Something I've discovered has me completely baffled.

When a vector is reallocated as a result of growing in size beyond its capacity, it creates a new array, moves (Thanks to C++11 capabilities.) the data over, then deletes the old array. When the old array is deleted, all of the destructors are called for the classes in the array.

Considering the classes were just moved (not copied) to a new memory location, what purpose can calling the destructors serve? Even if these classes had dynamically allocated memory, the addresses of that memory are still retained, no copy of that memory has been made, so no leak can occur. I absolutely cannot think of any reason that the destructors need to be called in this scenario, and I'm hoping there's just something I'm ignorant of.

If you know why this is done, or have any theories, please share.

Clipping

09 July 2010 - 04:37 PM

Is it possible to do clipping on polygons within your viewport, rather than manually changing the vertex positions yourself to accomplish the same appearance? I'm not entirely sure if I'm using the right terms to make this clear, but I can clarify if needed.

For example, if you're doing something like an editbox and you don't want the text (drawn with multiple rectangles, of course) to be drawn outside of the editbox rectangle's boundaries.

Index buffers

17 May 2009 - 05:46 AM

If you're using vertex data that never needs to be drawn more than once per frame, does an index buffer provide any benefit? As I understand it, the vertices can be cached, but if they're never being re-used, I'm not sure if that cache is beneficial in any way. If you're wondering why nothing would ever be re-used, it's for a 2D-only project. I didn't want to have to make a SetTransform and DrawPrimitive call for every single drawn rectangle. I don't anticipate many groupings of them to be used (as in small groups of rectangles to form a larger image), so that's why it's designed this way. This may not be ideal though, and I'm certainly open to discussion/suggestions.

PARTNERS