VCSBeam
Functions
buffer.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <mwalib.h>
#include "vcsbeam.h"
#include "gpu_macros.h"
Include dependency graph for buffer.c:

Functions

host_buffer * vmInitReadBuffer (size_t read_size, size_t copy_size)
 Initialise a buffer for reading in voltage data. More...
 
void vmFreeReadBuffer (host_buffer *rb)
 Frees the memory allocated in vmInitReadBuffer() More...
 
vm_error vmReadBufferCopyMargin (host_buffer *rb)
 Copy the data from the end of the read buffer to the beginning. More...
 

Function Documentation

◆ vmFreeReadBuffer()

void vmFreeReadBuffer ( host_buffer *  rb)

Frees the memory allocated in vmInitReadBuffer()

Parameters
rbThe read buffer to be freed
See also
vmInitReadBuffer()

◆ vmInitReadBuffer()

host_buffer* vmInitReadBuffer ( size_t  read_size,
size_t  copy_size 
)

Initialise a buffer for reading in voltage data.

Parameters
read_sizeThe size of the "read" portion of the buffer into which the data are read
copy_sizeThe size of the "copy" portion of the buffer
Returns
A pointer to a newly allocated read buffer

The read buffer is designed for situations where the data must be read in a section at a time, but where operations on the data require it to be treated list a continuous stream. In this regard, it is similar to a ring buffer. Here, however, the problem is solved by copying a portion of data at the end of the buffer to the beginning of the buffer at each successive read. For this to be efficient, the size of the needed overlap between consecutive sections must be small enough that copying the data around in this way does not carry a significant amount of overhead.

The relationship between the total buffer, the read buffer, and the copy buffer are illustrated in the following diagram.

<----------------------- buffer_size ------------------------->
<---------------- read_size -------------------->
<-copy_size-> <-copy_size->
|-------------|-----------------------------------|-------------|
^ ^ ^
buffer read_ptr copy_from_ptr
copy_to_ptr
See also
vmFreeReadBuffer()
vmReadBufferCopyMargin()
vmReadNextSecond()

◆ vmReadBufferCopyMargin()

vm_error vmReadBufferCopyMargin ( host_buffer *  rb)

Copy the data from the end of the read buffer to the beginning.

Parameters
rbThe read buffer to be operated on
Returns
VM_READ_BUFFER_NOT_SET if either rb or rb→buffer is NULL, or VM_SUCCESS if the memory is copied successfully.

This copies copy_size bytes from copy_from_ptr to copy_to_ptr. See vmInitReadBuffer() for a relevant diagram.

See also
vmInitReadBuffer()
vmReadNextSecond()