I am hoping someone may have a suggestion as to what is the best way to do what I need to do.
I am writing a program to simulate a physical system. The simplest analogy of what I need to do would be to simulate random walkers flowing down a tube. This, in itself, is relatively easy. However, there are two complicating factors. First, I need to generate new random walkers at regular intervals (of simulated time) at one end of the tube. Second, I need to monitor them while they are inside the tube, and then forget about them when they exit through the other end of the tube.
The way I would do it is with a vector of structs (sloppy code follows)
And then, down in the code
typedef struct _walkerType
... stuff I need for the walkers ...
std::vector< walkerType > walkers;
While I think this would work, I can see two big problems.
if ( time_is_right )
generateRandomInitialWalker(); // call it walker0, with activeFlag = 1
for ( i=0; i<walkers.size(); i++ )
if ( walkers[i].activeFlag )
if ( reach_other_end )
walker[i].activeFlag = 0;
time += delta_time;
1) After a while of running, most of the walkers would be inactive, yet I still have to loop through them
2) the vector could potentially become huge, gulping loads of memory.
Does anyone have any suggestion as to a better way to implement this?
Thanks a lot,