RingBuffer vs Flow Set Pool

<< Click to Display Table of Contents >>

Navigation:  Migration Guide for the Acquisition Stacks > CVBpy >

RingBuffer vs Flow Set Pool

What has changed?

In 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

devices = DeviceFactory.discover_from_root(DiscoverFlags.IgnoreVins)

with DeviceFactory.open(devices[0].access_token, AcquisitionStack.Vin) as device:

  stream = device.stream()

  stream.ring_buffer.change_count(5, DeviceUpdateMode.UpdateDeviceImage)

  stream.ring_buffer.lock_mode = RingBufferLockMode.On

  stream.start()

  images = []

  for _ in range(10):

      image, status = stream.wait_for(5000)

      if status == WaitStatus.Ok:

          images.append(image)

      elif (status == WaitStatus.Timeout and len(images) > 0):

          first = images.pop(0)

          first.unlock()

  stream.abort()

(4) Change the number of buffers in this ring buffer. Calling the change count function in mode update device image will discard all buffers, with which the device was created with and free the memory. Note that if the device does not support ring buffers the value of ring_buffer is None - when in doubt it's a good idea to check before accessing it.

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

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

(14) 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

devices = DeviceFactory.discover_from_root(DiscoverFlags.IgnoreVins)

with DeviceFactory.open(devices[0].access_token, AcquisitionStack.GenTL) as device:

   stream = device.stream(ImageStream)

  stream.register_managed_flow_set_pool(100)

   stream.start()

  for _ in range(10):

       image, status, node_maps = stream.wait()

      with image:

          pass

   stream.abort()

(4) With the function to register a managed flow set pool, it is possible to create an internal 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.

 

User-Allocated Memory (External Flow Set Pool)

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

 

Large Buffer Number Change

3rd generation stack

1

2

3

4

5

6

7

8

9

10

11

12

13

14

import cvb

devices = DeviceFactory.discover_from_root(DiscoverFlags.IgnoreVins)

access_token = devices[0].access_token

with DeviceFactory.open(access_token, AcquisitionStack.GenTL) as device:

   stream = device.stream(ImageStream)

  stream.register_managed_flow_set_pool(100)

   stream.deregister_flow_set_pool()

   stream.register_managed_flow_set_pool(200)

   stream.start()

  for _ in range(10):

       image, status, node_maps = stream.wait()

      with image:

          pass

   stream.abort()

(7) Calling the deregister flow set pull function between consecutive registrations reduces the memory consumption. The stream must be stopped.