Originally Posted by
grumpy
The problems aren't actually to do with memory allocation in this case. Look at the lines like this in the loop body
Code:
naaLeadBuffer[nLeadCount][nPos++] = (*pbuff[nLeadCount][nSampleCount
+ 2] + *pbuff[nLeadCount][nSampleCount + 3]) / 2;
Note the two bits I've highlighted in red and orange. Each of those is triple-dereferencing pbuff (for example, acting as if it is a two-dimensional array of pointers). However, pbuff is just a humble pointer to short, and cannot be triple-dereferenced.
pbuff actually is a pointer to a 2d short buffer...
Code:
short naaParseBuffer[12][buffsize];
{
----
-------
------
naaParseBuffer[10][nParseCount] = naFiltered[6];
naaParseBuffer[11][nParseCount] = naFiltered[7];
--------
-----
}
ProcessData(&naaParseBuffer[0][0],
nParseCount);
Code:
short CAppWnd::ProcessData(short *pbuff, unsigned int nParseCount)
{
unsigned short naaLeadBuffer[12][nParseCount];
unsigned int nBuffCount = nParseCount / 500;
unsigned int nPos = 0;
for(unsigned int nLeadCount = 0; nLeadCount < 12; nLeadCount++)
{
for(unsigned int nCount = 0; nCount <= nBuffCount; nCount
+= 500)
{
for(unsigned int nSampleCount = 0; nSampleCount < 500; nSampleCount
+= 10)
{
naaLeadBuffer[nLeadCount][nPos++] = (*pbuff[nLeadCount][nSampleCount
+ 2] + *pbuff[nLeadCount][nSampleCount + 3]) / 2;
naaLeadBuffer[nLeadCount][nPos++]
= *pbuff[nLeadCount][nSampleCount + 5];
naaLeadBuffer[nLeadCount][nPos++] = (*pbuff[nLeadCount][nSampleCount
+ 7] + *pbuff[nLeadCount][nSampleCount + 8]) / 2;
naaLeadBuffer[nLeadCount][nPos++] = *pbuff[nLeadCount][nSampleCount
+ 10];
}
}
}
return nParsecount;
}