copy/swap vector between threads...
-
Is it possible to swap vectors between threads using std::swap() instead of iterating one vector and copying each element (given that both vectors contain the exact same type of elements)? For example I have a structure/vector in my CMainFrame and in my CWinThread...
const struct s_list
{
CString strTimeStamp,
strStatus,
strID,
strIPRange,
strIPAddress,
strName,
strGUID,
strOS,
strResults;BOOL bUDPReply, bAgent;
};
std::vector<s_list> v_list;I am assuming it would be more efficient if I could swap the elements... The iteration/copy method works but it takes a good 30 seconds and hangs the application while its plowing through all the data. Any ideas? Thanks, Rob
Whoever said nothing is impossible never tried slamming a revolving door!
-
Is it possible to swap vectors between threads using std::swap() instead of iterating one vector and copying each element (given that both vectors contain the exact same type of elements)? For example I have a structure/vector in my CMainFrame and in my CWinThread...
const struct s_list
{
CString strTimeStamp,
strStatus,
strID,
strIPRange,
strIPAddress,
strName,
strGUID,
strOS,
strResults;BOOL bUDPReply, bAgent;
};
std::vector<s_list> v_list;I am assuming it would be more efficient if I could swap the elements... The iteration/copy method works but it takes a good 30 seconds and hangs the application while its plowing through all the data. Any ideas? Thanks, Rob
Whoever said nothing is impossible never tried slamming a revolving door!
Why swap or copy? Why not share the state? Pointer to the vector that you give to the thread.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Why swap or copy? Why not share the state? Pointer to the vector that you give to the thread.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
I have 2 threads that are pulling different portions of the data set. I wanted to merge the data into a single place to make it easier to work with and it seemed like a good idea to copy the whole vector from ThreadA (it does most the work) then iterate it and match it against the data in ThreadB. It may be easier to just break up the data and leave it in the threads. Thanks for the reply, - Rob
Whoever said nothing is impossible never tried slamming a revolving door!
-
I have 2 threads that are pulling different portions of the data set. I wanted to merge the data into a single place to make it easier to work with and it seemed like a good idea to copy the whole vector from ThreadA (it does most the work) then iterate it and match it against the data in ThreadB. It may be easier to just break up the data and leave it in the threads. Thanks for the reply, - Rob
Whoever said nothing is impossible never tried slamming a revolving door!
You haven't to actually break the data: you may give to each thread a vector of pointers to the proper elements of the original vector. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
You haven't to actually break the data: you may give to each thread a vector of pointers to the proper elements of the original vector. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
I have 2 threads that are pulling different portions of the data set. I wanted to merge the data into a single place to make it easier to work with and it seemed like a good idea to copy the whole vector from ThreadA (it does most the work) then iterate it and match it against the data in ThreadB. It may be easier to just break up the data and leave it in the threads. Thanks for the reply, - Rob
Whoever said nothing is impossible never tried slamming a revolving door!
RobJones wrote:
I have 2 threads that are pulling different portions of the data set.
How about passing the thread an iterator pair (i.e. a range[^]) it can operate on. Just need to make sure the thread alters data in place and doesn't modify (i.e. add or delete elements) the vector.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p