I am using a pair of pthreads that call a pair of functions for ping-pong dma data transfer that are used in a loop for data transfer from an acquisition board. For a large # of waveforms, I ultimately run out of PC memory and the program stops. At the end of each function I use the delete[] command to clear memory for reuse, but the pointer appears to advance by the array size used for the transfer until the location exceeds the 2 GB I have for memory. I can see this happening using the Task Manager performance button time plot and window of total memory used continuing to increase to the limit. The culprit for one of the functions (2nd) is:
unsigned char* dataBuffer2 = (unsigned char *) (pci_buffer2.UserAddr);
where pci_buffer1 and 2 have been set up and allocated in main. I also had the following line in each function process:
double* Rin = new double[length];
and it used up memory twice as fast. When I transferred the last line to an area just prior to main and used a constant 1024 for length, the program ran twice as far before exceeding system memory, so it appears that both lines were forcing new memory assignments and moving the pointers accordingly. In addition to using the delete[] command to free memory unsucessfuly at the end of each function procedure, I ended up closing the memory at the end of each procedure, then reallocating it again with the idea that the pointer would be set back to the original value, but it still seems to icrement along. So, neither approach appears to allow reuse of the memory because the pointer continues to march along. Any ideas how to solve this? Using Visual C++ 6.0 to compile.
void* threadFuncCompress2(int* count)
{
unsigned int PRF = 2000; // PRF in Hz
// unsigned int VelScale;
//casting to set the data array to an unsigned short array, changed to CHAR, 1-byte
unsigned char* dataBuffer2 = (unsigned char *) (pci_buffer2.UserAddr);// offending line, pointer
// double* RO = new double[length/1];
// double* IO = new double[length/1]; // both now prior to main,
// bulk of processing done here, then attempt to close memory and reallocate//
rc =PlxPciPhysicalMemoryUnmap(hDevice,&pci_buffer2);
// Release the buffer
rc =PlxPciPhysicalMemoryFree(hDevice,&pci_buffer2);
pci_buffer2.Size = mult3 + 256; //must be 256, not 32!
rc =PlxPciPhysicalMemoryAllocate(hDevice,&pci_buffer2,TRUE);
if (rc != ApiSuccess){
if(rc == ApiInsufficientResources) PlxPrintf("Insufficient Resources-\n");
else PlxPrintf("Error : Unable to allocate Buffers- reason unkown\n");
}
rc =PlxPciPhysicalMemoryMap(hDevice,&pci_buffer2);
if (rc != ApiSuccess)PlxPrintf("####Physical Memory Mapping Failed in Compress2 ###############");
//else PlxPrintf("\n\n\nPhysical Memory Mapped\n\n\n");