Answer the question
In order to leave comments, you need to log in
Constant requests to QMap or a local copy of the object. Where is the best performance?
Help to understand the issue. I am writing code using Qt. There is a named list QMap map.
What is the best way to perform multiple requests to the same list element, but requesting different fields of the structure?
There are two options:
Perform map.value("key").Struc-field each time; or make a local copy inside the function struct p = map.key..... and then access it p.Structure field??
It seems to me that map.value() is looking for the same element each time, which is somewhat illustrative. Please explain this point, or where to read?
Answer the question
In order to leave comments, you need to log in
Is your code slow? If so, then profile, and see where. If you haven't profiled it, then there's nothing to talk about performance :)
The value method will always return a copy of the value. Those. it is logical to save it somewhere if you need to access different fields several times. You can avoid copying by using an iterator or a constant reference + the [] operator on the map.
Read the official Qt documentation. You can also look at QHash, where the search is faster, but other restrictions are imposed on the key.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question