実行中に常にサイズと値が変化し続ける配列があります。可能な限り最小限のパフォーマンス オーバーヘッドでそれを実行したいと考えています。
配列サイズを変更する代わりに、開始インデックスと終了インデックスを示すメンバ int 変数を用意するだけで、この配列の消費者がこれらのインデックスを foor ループで使用することを期待します。リスクは、消費者が start および endindex を使用しない場合、エラーが発生する可能性があることです。それを行うより良い方法はありますか?
だから私が持っているのは:
MyClass
{
public:
BusinessClass myArray[MAX_COUNT];//the array
int StartIndex; //start index
int EndIndex; //End index
Logic()
{
//modified the array and changes start and end index
}
}
MyConsumer
{
MyClass obj;
public:
void ReadArray()
{
for (int i = obj.StartIndex ; i <obj.EndIndex; i++)
{
//perform logic
}
}
}