This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Thread safety of std::map for read-only operations
Having std::map a can we do a.find(...)->second in multiple threads at the same time on it?
Yes. As long as none of your threads do a write
i.e. Construct the data structure in memory
Use as many threads to find/read as you require.
If the leaf needs altering put a mutex there.
Related
This question already has answers here:
Does clearing a vector affect its capacity?
(4 answers)
C++ delete vector, objects, free memory
(7 answers)
Closed 3 years ago.
Sometimes I detect in different c++ projects code like this:
std::vector<DataClass> _dataVec;
...
std::vector<DataClass>().swap(_dataVec);
Is this code more effective than obvious and simple clear call
_dataVec.clear();
or these code samples have some kind of difference?
For what purpose I should prefer first variant?
This question already has answers here:
std::queue iteration
(10 answers)
Closed 3 years ago.
I was trying to iterate over a STL stack in c++ but was unable to do so.
Is it even possible to iterate over a C++ STL Stack or Queue without popping(Like vectors)?
No, you cannot iterate over a std::queue since that is not its purpose.
A container that allows fast insertion at both ends, as well as iteration, is std::deque. Note that iteration is slower than for a std::vector, but insertion/removal at the beginning is much faster.
This question already has answers here:
How to determine CPU and memory consumption from inside a process
(10 answers)
Closed 7 years ago.
I have a few threads in my program - run on Windows and write in C++.
How can I know in the end of the running how much CPU time is used by all or one of them?
You can use the GetThreadTimes function: https://msdn.microsoft.com/en-us/library/windows/desktop/ms683237%28v=vs.85%29.aspx
This question already has answers here:
C++ cache aware programming
(10 answers)
Closed 7 years ago.
I am profiling my code on various CPUs running Windows7 and my results so far suggest that I need to tune a buffer size proportional to the machine's L2CacheSize or L3CacheSize. Is there a way to obtain these parameters from C++?
You can use the GetLogicalProcessorInformation function to get that. It returns an array of SYSTEM_LOGICAL_PROCESSOR_INFORMATION structures which contain a CACHE_DESCRIPTOR structure, which provides the cache size information.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
threadpool in c++
I need to write my own or use already written thread's pool in C++ with priorities. Boost threadpool is too complicated. Please, advice me one.
If you have a basic understanding of how to write a simple threadpool with std::queue, change std::queue to std::priority_queue and you will get a threadpool with priorities