When all you need is the random access of a C array (or
maybe even less,
just sequential acces), and this is something you should know _before
writing one letter of code_, why waste your time by writing it first using
a vector and changing it afterwards ? Just write it using an array _from
the start_. It takes no more time or effort than using a vector.
two comments. one is a repeat, because i don't think my original
message made it through from several days ago. the repeat is only
vaguely related to this post.
a) (the new one) sometimes you simply *don't* know whether you need the
random access of a C array or the properties of a singly-linked list
or the properties of a doubly-linked list, let alone the additional
heuristics of a set, a FIFO queue etc. the nice thing about a
design pattern like STL containers is that you can toggle back and
forth between any all of them with almost no work. i can't count how
many times in ardour i have changed:
typedef vector<Foo> Foos;
to
typedef list<Foo> Foos;
or some other STL container. 95% of the time, thats the only change in
the code i have to make. if you really know and understand all the
parameters of the software design up front, this isn't useful, but i
haven't written a single piece of software where this claim was true :)
b) (repeat) i have no doubt that there are many areas where ardour
(for example) contains code much, much slower than the equivalent in
SAWstudio, which is written in 90%+ assembler. however, on a project
whose development alone takes many years and has seen a 7-9 fold speed
up in processor speeds, i would rather concentrate on algorithmic
design (for example, avoiding silly arbitrary limits, ensuring maximal
flexibility even if its not intended to be exposed to the user
etc). i'll leave "making things as fast as possible" to intel, AMD and
the gcc team.
--p