Skip to content

Instantly share code, notes, and snippets.

Created Dec 19, 2013
What would you like to do?
class volk_qa_mem_pool
/* QA mem pool returns an aligned and unaligned buffer with sizes
* of N * itemsize. The buffers do not overlap so that the user
* need not be concerned about reallocating identical vectors.
* This class exists mostly to guarantee that allocated buffers
* are cleaned up properly on exit
void get_32f_data(float* data_a, float* data_u, int N)
size_t alignment = volk_get_alignment();
// Notice (alignment) here not (alignment-1) like original.
// We do this so that the (data_u+1) later on will always
// be in the range of what we allocated.
float *align = (float*)malloc((N + alignment) * sizeof(float));
float *unalign = (float*)malloc((N + alignment) * sizeof(float));
memset(align, 0, (N + alignment) * sizeof(float) );
memset(unalign, 0, (N + alignment) * sizeof(float) );
// Store the original memory locally to delete properly when destroyed
// Get's data_a aligned to alignment requirement
data_a = (((unsigned long)algin + alignment-1) & ~(alignment-1));
// Makes sure that we are off by 1 item in memory, which (almost) has to be unaligned
data_u = (((unsigned long)unalign + alignment-1) & ~(alignment-1)) + 1;
std::list<std::vector<float*> > _mem;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment