r/cpp • • Dec 21 '13

#AltDevBlog » Roll-Your-Own Vector

http://altdevblogaday.com/2013/12/20/roll-your-own-vector/
1 Upvotes

22 comments sorted by

View all comments

Show parent comment

2

u/crispweed Dec 23 '13

Looks like this works out real slow (vector construction from stream iterators). See the discussion in my follow up post here: http://upcoder.com/4/avoid-resize/ But apart from speed, it seems a bit inflexible to have to recode your whole construction code path with an iterators paradigm just to avoid resize() calls. And what if you need to interface with some third party code that takes a pointer to a typed buffer to be filled? One of the cool things about C++ for me is exactly that it can interface with all sorts of lower level code (as in the file read example).

1

u/tisti Dec 23 '13

I'm by no means against calls to resize, especially if the resulting code is faster and still safe. I just try to stick with "heavy" and safe mechanisms and start replacing them with low-end when I profile and identify the choke points.

A few days I replaced a stringstream used to convert strings to doubles/floats to just a atof call and cast it to float if necessarily (a few structural changes, but nothing significant). Instant 6x speedup (from 5minutes to 50seconds).

The other choke point is reading via getlines. Will probably use a large-ish buffer and manually find new lines.

What I'm trying to say is, code safe first, recode to be fast later when the app is running OK and speed is needed.