# Getting Started with CVB.Net

**URL:** <https://forum.commonvisionblox.com/t/getting-started-with-cvb-net/246>\
**Category:** .Net API\
**Tags:** csharp, tutorial\
**Created:** [September 9, 2019, 10:00pm UTC](https://forum.commonvisionblox.com/t/getting-started-with-cvb-net/246 "2019-09-09T22:00:00Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![parsd](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/parsd/32/7_2.png) [@parsd](https://forum.commonvisionblox.com/u/parsd)\
**Post date:** [September 11, 2019, 11:54am UTC](https://forum.commonvisionblox.com/t/getting-started-with-cvb-net/246/14 "2019-09-11T11:54:42Z")

</div>

# `RingBuffer` Fill Level

This is for when you want to monitor if your processing can keep up with the incoming images. It is based on the post:

> [@parsd](#):
>
> # Stream Statistics

## Interlude: The `IRingBuffer` Interface

_Vin_ drivers receive e.g. image data as frames from a camera. This data needs to be stored somewhere: in a buffer, which is a contiguous chunk of memory. A ring buffer is a circular buffer used to store multiple of these buffers. It is called ring buffer, because single buffers are “taken” from it and “returned” if not needed anymore. If you reached the last buffer in the ring buffer, the first one is retrieved – and thus ring closes. With this data structure you can go on acquiring image data for as long as you wish with a finite and constant amount of memory used.

Aside from the ring buffer’s basic properties we use it for these three main reasons:

1. Enable parallel acquisition and processing

2. Compensate for varying processing times

3. Improve acquisition speed and reduce memory fragmentation

We will see more of the `IRingBuffer` interface in later posts. You can do a lot of cool stuff with it.

Most of the _vin_ drivers (including the aforementioned _GenICam.vin_) support the `IRingBuffer` interface. This can be queried by the presence of an `IRingBuffer` object on the `Stream`:

> `bool isPresent = device.Stream.RingBuffer != null`

## Useful Measurement Points

Virtually all _vin_ drivers supporting the `IRingBuffer` interface have these statistics:

- `StreamInfo.NumBuffersPending`

- `StreamInfo.NumBuffersLocked`

These two in combination with the `device.Stream.RingBuffer.Count` property (or `StreamInfo.NumBuffersAnnounced` statistic if available) gives you all information necessary to evaluate the acquisition engine status.

If `NumBuffersPending` increases, you fall behind the acquisition rate. This needn’t be bad if you anticipated this. Reasons can be the processing time peaks mentioned in the `IRingBuffer` section or you acquire multiple images in bursts to process them as a group.

If at any point in time `NumBuffersLocked` equals the number of buffers in the `IRingBuffer` (`.Count`), you are prone to loose images. If such a _buffer overflow_ happens, `NumBuffersLostLocked` is increased. This is a counter that is reset on acquisition `.Start`.

If you want to keep track on the amount of lost images between two `.Wait` calls you need to store that data and calculate the difference yourself. We don’t do the bookkeeping to be as lean as possible in our acquisition engine (also we don’t know your actual use case: could be simply that, a series of lost frames measured at certain points in time or actually the total number as returned).

Symptoms of too few buffers are, in addition to the lost image data, unexpected drops in acquisition framerate. You can increase the number of buffers either in the driver’s configuration file, which can be found at _%CVBCONFIG%Drivers_, or programatically via

> `device.Stream.RingBuffer.ChangeCount(newSize, DeviceUpdateMode.UpdateDeviceImage);`

`UpdateDeviceImage` is the default change mode, `NewDeviceImage` is used in scenarios when you switch the ring buffer count while still processing image data.

---

_[View the full topic](https://forum.commonvisionblox.com/t/getting-started-with-cvb-net/246)._
