0

i have a bunch of data i want to pass to CreateThread. i created a struct as per the msdn documentation. here it is:

typedef struct ThreadRecvData
{
	std::list<char> data;
	Ogre::String addr;
	unsigned long port;
} THREADRECVDATA, *PTHREADRECVDATA;

then i initialise the struct, again as per the msdn documentation:

PTHREADRECVDATA pThreadRecvData;
pThreadRecvData = (PTHREADRECVDATA) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(THREADRECVDATA));
pThreadRecvData->addr = "123";
pThreadRecvData->port = 123;
pThreadRecvData->data.push_back('x');

i get a crash at pThreadRecvData->data.push_back('x').

can anyone help ?

thank you.

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by unclepauly
0

You probably can't use HeapAlloc() to allocate memory for pThreadRecvData because std::list allocated memory from the standard heap using new operator. Replace HeapAlloc() with new and retest.

0

You probably can't use HeapAlloc() to allocate memory for pThreadRecvData because std::list allocated memory from the standard heap using new operator. Replace HeapAlloc() with new and retest.

i used new and yes it does indeed work. i wanted really to understand what was happening - so thanks for the explanation.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.