0

I have 200 groups. Each group has 100 devices, i.e. a total of 20000 devices divided into 200 groups of 100 each.

Now when each device gets registered with the server, the server assigns a group id to the device. (100 devices has same group id.) At a later stage the server sends the multicast data with the group id so that the data is received to all the devices having that group id.

The problem is that I need to allocate a single chunk of memory(say 25bytes) for each group to store the data so that all the devices in that group will use that chunk for their processing. My idea is to allocate a big chunk (say 25 * 200 = 5000 bytes) and assign each group a 25 byte block (grp0 points to start address, grp1 points to start+25 address and so on).

Is this the best way? Any other ideas?

4

2 に答える 2

1

あなたの例では、配列を使用します。

クライアントの数が変わらない場合、1 つのブロックを割り当てるのが最も効率的な方法です。

  • 100回ではなく1回のmalloc呼び出しを行います
  • すべてのメモリブロック割り当てを追跡するリストに関連するオーバーヘッドを回避します
  • データは 1 つの部分に保持されるため、100 個の小さなブロックをどこに配置するかに比べて、プロセッサ キャッシュでより簡単にキャッシュできます。

おそらく 100 個の要素だけの違いは無視できるほどですが、200 個のグループを掛けるとパフォーマンスが向上する可能性があります (実際にはデータ構造の使用方法に依存します)。

代わりに動的構造の場合 (たとえば、クライアントが接続して切断するため、常に 100 とは限らない)、必要に応じてメモリを割り当てるリンク リストを使用する必要があります (したがって、100 個の異なるメモリ ブロックが作成されます)。

于 2012-11-08T11:43:41.483 に答える
0

ArjunShankarが述べているように、グループ内のデバイスにアクセスするにはO(1)の時間がかかります。これは、特定のデバイスを見つけるためにあまり処理する必要がないことを前提とすると、悪くありません(デバイスを見つける必要があると仮定します)。それらを同時に処理することを計画していて、その数が大きくなる(または使用可能なメモリが制限される)場合は、ディスクページネーションなどのいくつかの手法を確認する必要があります。

于 2012-11-08T11:43:30.127 に答える