|
|
On 14/05/2013 06:04 PM, Warp wrote:
> When using the standard containers, one should know how they work and
> what they are doing, in terms of efficiency. For example, passing them
> by value eg. as function parameters is inefficient, and that should always
> be done by reference, if possible.
How about std::string? Presumably it's a bad idea to pass that by value
either...
> And also, of course, use the right tool for the job. It makes no sense
> to use, for example, std::list for something that std::vector will do.
> And if your array is of static size, use std::array instead of std::vector
All this stuff is pretty dynamic. I have no idea how big the expression
I'm parsing will be until after I finish parsing it.
I'm sure if you could see my code, you'd probably have a heart attack
over all the highly inefficient stuff it's doing. Then again, it gets
run once at application start-up, parsing a few dozen strings that are
mostly a dozen characters long each, so...
(Perhaps the biggest inefficiency is having a lot of zero-element
vectors laying around. I have no idea what the space overhead for that
is. But I also have no idea how to avoid it.)
Post a reply to this message
|
|