Ringbuffer vs Flow Set Pool

<< Click to Display Table of Contents >>

Navigation:  Migration Guide for the Acquisition Stacks > CVB C# >

Ringbuffer vs Flow Set Pool

What has changed?

With the 3rd generation stack the ring buffer is replaced by the managed flow set pool.

 

Code Examples

2nd generation stack

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

using (var devices = DeviceFactory.Discover(DiscoverFlags.IgnoreVins))

{

  using (var device = DeviceFactory.Open(devices[0], AcquisitionStack.Vin))

   {

      var stream = device.Stream;

      stream.RingBuffer.ChangeCount(5, DeviceUpdateMode.UpdateDeviceImage);

      stream.RingBuffer.LockMode = RingBufferLockMode.On;

      stream.Start();

      List<StreamImage> images = new List<StreamImage>();

      for (int i = 0; i < 10; i++)

       {

          var image = stream.WaitFor(UsTimeSpan.FromSeconds(5),

             out WaitStatus status);

          if (status == WaitStatus.Ok)

           {

              images.Add(image);

           }

          else if (status == WaitStatus.Timeout && images.Count > 0)

           {

              (images[0] as RingBufferImage).Unlock();

              images.RemoveAt(0);

           }

       }

      images.Clear();

      stream.Abort();

   }

}

(6) Changes the number of buffers in the stream's ring buffer. Calling the ChangeCount function in mode update device image will discard all buffers, with which the device was created with and free the memory before reallocating the new buff. Note that the RingBuffer property may be null if the device does not support ring buffers - check before accessing if you are uncertain.

(7) Activates the lock mode of the ring buffer. The buffer is unlocked automatically when running out of scope and the image is not stored.

(18) Wait returns with the wait result, also containing the stream image, when the ring buffer interface is available on the device.

(20) This unlocks the ringbuffer if the lock mode is on, so the buffer is returned into the acquisition queue.

 

3rd generation stack

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

using (var devices = DeviceFactory.Discover(DiscoverFlags.IgnoreVins))

{

  using (var device = DeviceFactory.Open(devices[0], AcquisitionStack.GenTL))

   {

      var stream = ((GenICamDevice)device).GetStream<ImageStream>(0);

      stream.RegisterManagedFlowSetPool(100);

      stream.Start();

      for (int i = 0; i < 10; i++)

       {

          using (var image = stream.Wait(out WaitStatus status))

           {

              using (var nodeMaps = NodeMapDictionary.FromBuffer(image))

               {

                  // do something with the composite and the node map

               }

           }

       }

      stream.Abort();

   }

}

(6) With the function to register a managed flow set pool, you can create an internally managed flow set pool with the given size. Any previously registered flow set pool will be removed from the acquisition engine after the new flow set pool was created.

 

Large Buffer Number Change

3rd generation stack

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

using (var devices = DeviceFactory.Discover(DiscoverFlags.IgnoreVins))

{

  using (var device = DeviceFactory.Open(devices[0], AcquisitionStack.GenTL))

   {

      var stream = device.GetStream<ImageStream>(0);

      stream.RegisterManagedFlowSetPool(100);

      stream.DeregisterFlowSetPool();

      stream.RegisterManagedFlowSetPool(200);

      stream.Start();

      for (int i = 0; i < 10; i++)

       {

          using (var image = stream.Wait(out WaitStatus status,

             out NodeMapDictionary nodeMaps))

           {

              nodeMaps.Dispose();

           }

       }

      stream.Abort();

   }

}

(7) Calling the DeregisterFlowSetPool() function between flow set pool registrations helps keep the memory consumption of the software low (otherwise memory usage would spike for a short moment to the sum of the currently used pool and the new pool). Note that a running stream must be stopped prior to registering or deregistering a flow set pool.

 

User-Allocated Memory (External Flow Set Pool)

The external flow set pool is only available in C++: Ringbuffer vs Flow Set Pool