Multi-Threaded Memory Preallocation 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:

Thread A:

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

Thread B:

int index1 = 0;
char* newData = getData(...); // get a pointer to 30 MB of data
memcpy(&amp;myMemory[index1*30*1024*1024], &amp;newData[0], 30*1024*1024];
SetEvent(...) // tell Thread C that I have written new data

// use index i as circular Buffer
if (index1 &lt; 10)
 index1++;
else
 index1 = 0;


In Thread C, when new data is written, I need to get it and process it

Thread C:

int index2 = 0;
char* dataToProcess[] = new char[30*1024*1024];
if (event Fires) // if event in Thread B is set
 memcpy(&amp;dataToProcess[0], &amp;myMemory[index2*30*1024*1024], 30*1024*1024];
 processData(dataToProcess)

// use index i as circular Buffer
if (index2 &lt; 10)
 index2++;
else
 index2 = 0;
Another approach I can think of could be this. Get rid of myMemory altogether. Once you receive data in thread B, allocate memory and copy that data (as you're doing now). Send thread C a message that data is received. Once thread C copies the data into its internal buffer, thread C can send message back to thread B that the data has been copied. Thread B then deallocate the buffer.

Your design seems fine to me. Yet another approach could be avoiding the data copy in thread C.

int index2 = 0;
char* dataToProcess;
if (event Fires) // if event in Thread B is set
 dataToProcess = &amp;myMemory[index2*30*1024*1024];
 processData(dataToProcess)
// Rest of the code