Author Topic: Performance series - STL types: reserve(), capacity() and size()  (Read 1018 times)

0 Members and 1 Guest are viewing this topic.

Offline Echelon9

  • 210
Performance series - STL types: reserve(), capacity() and size()
I've recently pruned from the code base a number of similar code patterns, best exemplified by:

Code: [Select]
--- trunk/fs2_open/code/graphics/gropenglshader.cpp 2011/10/17 13:01:48 7914
+++ trunk/fs2_open/code/graphics/gropenglshader.cpp 2011/10/17 13:07:24 7915
@@ -504,8 +504,6 @@
  bool main_vert = cf_exists_full("main-v.sdr", CF_TYPE_EFFECTS) != 0;
  bool main_frag = cf_exists_full("main-f.sdr", CF_TYPE_EFFECTS) != 0;
 
- GL_shader.reserve(Num_shader_files+1);
-
  for (idx = 0; idx < Num_shader_files; idx++) {
  bool in_error = false;
  opengl_shader_t new_shader;

Broadly, STL types handle their own in-memory locations and reallocations. While STL types do require a copy/realloc operation when they fully utilise their capacity() this is an operation best left to the underlying implementation of the STL on your system.

Why?

Next post I'll go into methods to be used to profile the impact of small code changes.
« Last Edit: October 17, 2011, 08:39:43 am by Echelon9 »