GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 14-Apr-2009, 12:26
cacoder cacoder is offline
New Member
 
Join Date: Dec 2007
Location: detriot
Posts: 13
cacoder is on a distinguished road

std map to vector for waitformultipleobjects parameter


Hi,

I have a set of channel objects. Each channel has a set of Win32 event objects associated with it. I want to store the Win32 event objects in a std::map as follows:

CPP / C++ / C Code:

std::map<unsigned int, std::vector<HANDLE>> channel_events;

for(unsigned int ch_index = 0; ch_index < 5; ch_index++)
{
  for(unsigned int event_index = 0; event_index < 4; event_index++)
  {
    channel_events[ch_index].push_back(CreateEvent(...));
    channel_events[ch_index].push_back(CreateEvent(...));
    channel_events[ch_index].push_back(CreateEvent(...));
  }
}

The problem is WaitForMultipleObjects(...) requires the event handles to be passed in as a const HANDLE *. So I can pass in a vector<HANDLE> as &events but I need to pass in the std::map above. Any ideas? I could always construct the std::map as an std::vector by sequentially ordering channel events into a long std::vector but not sure that's the best approach.

-cacoder
Last edited by admin : 14-Apr-2009 at 21:34. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #2  
Old 14-Apr-2009, 19:54
dlp dlp is offline
Member
 
Join Date: May 2006
Posts: 157
dlp has a spectacular aura about

Re: std map to vector for waitformultipleobjects parameter


If you're trying to wait for all the HANDLE objects in the map, you won't be able to do it this way. The alternative is to create an array of HANDLE and copy each handle into that as well as store it in your map. Question though, if both the event_index and the ch_index values go from 0 to some number continously, why not just use either a 2 dimensional array or 2 dimensional vector?

CPP / C++ / C Code:
std::vector< std::vector< HANDLE > > channel_events(5);
for(unsigned ch_index = 0; ch_index < 5; ch_index++)
{
  for(unsigned event_index = 0; event_index < 4; event_index++)
  {
    channel_events[ch_index].push_back(CreateEvent());
  }
}
  #3  
Old 15-Apr-2009, 18:25
cacoder cacoder is offline
New Member
 
Join Date: Dec 2007
Location: detriot
Posts: 13
cacoder is on a distinguished road

Re: std map to vector for waitformultipleobjects parameter


You are correct in that I could just use a two dimensional vector. I decided to just use a one dimensional vector and have an enum index all events in the vector. It keeps the design simple.
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Minimum value parameter problem tones1986 C++ Forum 3 03-Apr-2006 10:46
find the value in the array that is closest in value to the second parameter jack223 C++ Forum 4 04-Nov-2005 07:58
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 21:30
Re: Command Line Arguments, Part 1 WaltP C Programming Language 0 11-Jul-2004 00:34
Re: Programming Techniques WaltP C Programming Language 0 10-Mar-2004 00:56

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:50.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.