I need to figure out the best way to deal with memory pre-allocation
Below is pseudo-code for what I am doing now, and it seems to be working fine.
I am sure there is a better way to do this, I would like to see if anyone has any good idea.
In Thread A I need to allocate 300 MB of memory and zero it out:
char* myMemory = new char[10*30*1024*1024];
In Thread B I incrementally get 10 sets of data 30 MB each. As I get this data it must be written to memory
int index1 = 0; char* newData = getData(...); // get a pointer to 30 MB of data memcpy(&myMemory[index1*30*1024*1024], &newData, 30*1024*1024]; SetEvent(...) // tell Thread C that I have written new data // use index i as circular Buffer if (index1 < 10) index1++; else index1 = 0;
In Thread C, when new data is written, I need to get it and process it
int index2 = 0; char* dataToProcess = new char[30*1024*1024]; if (event Fires) // if event in Thread B is set memcpy(&dataToProcess, &myMemory[index2*30*1024*1024], 30*1024*1024]; processData(dataToProcess) // use index i as circular Buffer if (index2 < 10) index2++; else index2 = 0;