dimanche 24 février 2013

Test Number 2


Author:       François PIETTE @ OverByte
Creation:     Feb 16, 2013
Description:  TCommQueue is a generic class aimed at handling "buffers" in
              an efficient way so that it can be used in high speed systems.
              The idea is to have the minimum number of memory allocation.
              To manage the buffers, the class uses 3 linked lists: Active,
              inactive and acquired buffers.
              When adding a buffer to the queue, the Add method first look at
              the inactive queue to get an inactive buffer and reuse it. If
              no inactive buffer is available, then a new one is allocated.
              When a buffer is not more needed, the remove method actually move
              the buffer to the inactive buffer list.
              The queue offers methods to iterate thru it: first, next, previous
              and last. Each method return a pointer to the buffer.
              The class is multithread safe: it make use of a critical section
              to protect his internal data structures.
              To be completely thread safe according to the producer/consumer
              pattern, there are a pair of additional methods: AcquireItem and
              ReleaseItem. AcquireItem will get a pointer to the oldest buffer
              in the queue and move it to the acquired buffer list. Only a
              single thread is able to get a pointer to a given buffer.
              Once a thread has finished processing the buffer, it must call
              the ReleaseItem method passing the pointer so that the buffer is
              moved to the inactive list for later reuse.
              A last method, FreeAllInactiveItems, can be use to free all
              inactive buffer. This should probably never used unless the
              application is short of memory. Freeing all inactive buffer
              obviously frre memory, but has an impact on performance: new
              buffer must be allocated.
              On my system, allocating one million of buffers having 0.5 kB each
              takes 265 mS the first time. It takes 109 mS to remove all.
              Then it only takes 145 mS to get another one million buffers.
              It goes faster the second (and subsequent times) because no
              memory allocation take place. Only pointers in the linked lists
              are updated.
              Note about multithreading support: All operations on the linked
              lists are protected by a critical section so each list will
              remain coherent even if different threads use the same queue at
              the same time. However, if several thread have to process items
              in the queue (consumers), they MUST use AcquireItem and
              ReleaseItem exclusively. Other methods are for a single consumer
              thread. In all cases, multiple thread can be producers, that is
              add items in the queue.
Version:      1.00
History:


Aucun commentaire:

Enregistrer un commentaire