Tuesday, August 27, 2013

Turning stl::vector<> into an array

General concepts, things to change in the code:

  1. Change use of 'iterator' into 'int'.  Very simple, modify 'begin() and 'end()' to reflect 0, and current last element.
  2. begin() is just '0'.  if 'end()' is 0, then the vector is empty.  
  3. Just add these methods to a class that contains the array, and keep a maximum size of the array. *Allocate that size on initialization*.
  4. It can be static or from a pool.  This helps fix the memory fragmentation problems that occur when allocations and frees occur while the app executes in real time.

No comments:

Post a Comment