Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

16
  • Wow, my system shows a 30% improvement in the VLA version over std::vector. Commented Mar 14, 2013 at 14:15
  • 1
    Well, try with size-range of about 5-15 instead of 20-200, and you'll probably have a 1000% or more improvement. [Also depends on compiler options - I will edit the above code to show my compiler options on gcc] Commented Mar 14, 2013 at 14:18
  • I just added a func3 which uses v.push_back(rand()) instead of v[i] = rand(); and removes the need for resize(). It takes about 10% longer compared to the one using resize(). [Of course, in the process, I found that the use of v[i] is a major contributor to the time the function takes - I'm a little surprised about that]. Commented Mar 14, 2013 at 14:46
  • 1
    @MikeBrown Do you know of an actual std::vector implementation which would use VLA/alloca, or is that just speculation? Commented Mar 14, 2013 at 14:47
  • 3
    The vector does indeed use an array internally, but as far as I understand, it has no way to use a VLA. I do believe my example shows that VLA's are useful in some (perhaps even many) cases where the amount of data is small. Even if the vector ues VLA's, it would be after additional effort inside the vector implementation. Commented Mar 14, 2013 at 15:11