Cross threads memory free?
What do you people free the meory if it's NEW at one thread, and needs to be used in another thread?
I try to free it in the received thread, but get error message at debug environment.
Code may look like:
Thread A:
char* pBuffer = new char[nLength]; //New memory
strcpy((char *)pBuffer, (LPCTSTR) strPacket);
m_pCWndParent->PostMessage(WM_GETBUFFER,
(WPARAM)nLength, (LPARAM)pBuffer);
Thread B:
BOOL CxxxDlg::ReceivedData(int nByte, char* pBuffer)
{
....
CString strBuffer = pBuffer;
....
delete pBuffer;//ERROR while running here
}
It seems I cannot free the meory in another thread? Then where is the suitable place for me to free the memory?
[802 byte] By [
myron] at [2007-11-20 1:26:51]

# 1 Re: Cross threads memory free?
The error message I encounter is at:
VC98/CRT/SRC/DBGHEAP.C
if (!CheckBytes(pbData(pHead) + pHead->nDataSize, _bNoMansLandFill, nNoMansLandSize))
_RPT3(_CRT_ERROR, "DAMAGE: after %hs block (#%d) at 0x%08X.\n",
szBlockUseName[_BLOCK_TYPE(pHead->nBlockUse)],
pHead->lRequest,
(BYTE *) pbData(pHead));
any suggestion?
myron at 2007-11-9 13:59:09 >

# 3 Re: Cross threads memory free?
Ehh... sorry, that it's a typo.
using delete [],
you got the same error message at the place I posted.
Is there anyone ever handle the memory thing during different threads?
myron at 2007-11-9 14:01:09 >

# 4 Re: Cross threads memory free?
Sorry that I cannot upload the error message because of proxy server problem.
The error message running at the code is:
Debug Error!
Program: ....../ ... /... .exe
DAMAGE: after Normal block (#114) at 0x00.......
(Press Retry to debug the application)
myron at 2007-11-9 14:02:03 >

# 5 Re: Cross threads memory free?
Found the reason after tracing HEAP.
Originally nLength is the lenght of strPacket, and that's too small to keep the data on the heap.
I increae the nLength by 1, and this problem is solved.
Thanks for anyone caring about this problem.
myron at 2007-11-9 14:03:13 >
