passing params to CreateThread

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2006
Posts: 36
Reputation: unclepauly is an unknown quantity at this point 
Solved Threads: 0
unclepauly unclepauly is offline Offline
Light Poster

passing params to CreateThread

 
0
  #1
Sep 28th, 2008
i have a bunch of data i want to pass to CreateThread. i created a struct as per the msdn documentation. here it is:

  1. typedef struct ThreadRecvData
  2. {
  3. std::list<char> data;
  4. Ogre::String addr;
  5. unsigned long port;
  6. } THREADRECVDATA, *PTHREADRECVDATA;

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

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

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

can anyone help ?

thank you.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1462
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: passing params to CreateThread

 
0
  #2
Sep 28th, 2008
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 36
Reputation: unclepauly is an unknown quantity at this point 
Solved Threads: 0
unclepauly unclepauly is offline Offline
Light Poster

Re: passing params to CreateThread

 
0
  #3
Sep 28th, 2008
Originally Posted by Ancient Dragon View Post
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC