I need to figure out the best way to deal with memory pre-allocationBelow 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 memoryThread B:int index1 = 0;char* newData = getData(...); // get a pointer to 30 MB of datamemcpy(&myMemory[index1*30*1024*1024], &newData[0], 30*1024*1024];SetEvent(...) // tell Thread C that I have written new data// use index i as circular Bufferif (index1 < 10) index1++;else index1 = 0;In Thread C, when new data is written, I need to get it and process itThread C:int index2 = 0;char* dataToProcess[] = new char[30*1024*1024];if (event Fires) // if event in Thread B is set memcpy(&dataToProcess[0], &myMemory[index2*30*1024*1024], 30*1024*1024]; processData(dataToProcess)// use index i as circular Bufferif (index2 < 10) index2++;else index2 = 0;
Multi-Threaded Memory Preallocation
c++;multithreading