Skip to content

Buffer Rotation

Josh Weinstein edited this page Jun 22, 2018 · 4 revisions

rotation

Intro

In order for Wind to continuously transform and flow data without new allocation or deallocation, it needs to rotate and swap buffers. There are two main buffers, the active, and inactive buffers. They are held as static arrays in WindData.c, and controlled with a boolean value that determines which buffer is the active and which is the inactive one.

static unsigned char WindData_B0[WindData_BUF_SIZE];
static unsigned char* WindData_B0_BEGIN = WindData_B0;
static unsigned char* WindData_B0_END = WindData_B0 + WindData_BUF_SIZE;

static unsigned char* WindData_B0_PTR = WindData_B0;

static unsigned char WindData_B1[WindData_BUF_SIZE];
static unsigned char* WindData_B1_BEGIN = WindData_B1;
static unsigned char* WindData_B1_END = WindData_B1 + WindData_BUF_SIZE;

static unsigned char* WindData_B1_PTR = WindData_B1;

And the state maintainer:

static int WindData_ACTIVE_B = 1;

In all of the reading and writing methods for the buffers, WindData_ACTIVE_B essentially routes the calls to the respective buffer. After each transformation call, the buffers rotate, via this call

void WindData_active_switch(void)
{
        WindData_ACTIVE_B = !WindData_ACTIVE_B;
}
Clone this wiki locally