Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Echelon9 on October 17, 2011, 08:21:15 am

Title: Performance series - STL types: reserve(), capacity() and size()
Post by: Echelon9 on October 17, 2011, 08:21:15 am
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 (http://www.cplusplus.com/reference/stl/vector/). 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.