Page 3 of 5

Use and abuse of STL vector

Posted: October 12th, 2010, 11:37 am
by renorm
You can make e_ and j_ vectors and save on copy control.

Use and abuse of STL vector

Posted: October 13th, 2010, 3:18 pm
by Cuchulainn
QuoteOriginally posted by: renormHow about this. It should work well for matrices with many more rows than columns.How about views, ranges and slices of this matrix structure? difficult?

Use and abuse of STL vector

Posted: October 14th, 2010, 4:12 pm
by renorm
How about this? Is it legal?

Use and abuse of STL vector

Posted: October 14th, 2010, 4:19 pm
by renorm
SSE instructions work with buckets of 4 floats. If you have 11 floats, it is easier and faster to process them as 3 buckets and then discard 12th element, instead of processing them as 2 buckets plus a non-SSE branch for the remaining 3 elements. User code would see vector v as 11 elements big, while SSE subroutine could treat array a as if it has 12 elements .

Use and abuse of STL vector

Posted: October 14th, 2010, 10:07 pm
by mj
QuoteOriginally posted by: renormHow about this? Is it legal?would it work? probablyThe vector wouldn't change its memory for a shrink in size so you wouldn't have memory problems. v[11] is equivalent to *(v.begin()+11)24.1.5 "The library never assumes that past-the-end values are dereferenceable."However, you are doing a[11] not v[11] so the issue is solely whether the memory would shrink. A quick look at the standard was not overly clear. There is an implication that as long as the capacity does not increase the memory will not be reallocated so you should be ok.

Use and abuse of STL vector

Posted: October 15th, 2010, 1:57 am
by mj
reading the standard a bit more.An insert is not supposed to cause a reallocation unless the capacity is exceeded, and all iterators that point to before the new end after a resize are supposed to remain valid if it's a shrink.It's difficult to see how this could be achieved without it being safe to use the memory off the end of the vector below the capacity size.

Use and abuse of STL vector

Posted: October 15th, 2010, 8:59 am
by renorm
Very good point regarding iterators.I took a look at STLs on my PC. Both Visual C++ and MinGW use SGI STL implementation. I presume the same is true for GCC and many other implementations. SGI vector never shrinks its capacity on its own.

Use and abuse of STL vector

Posted: October 15th, 2010, 12:22 pm
by renorm
POD has no destructors. "the swap trick" can remove the hidden tail. But as mj pointed out, shrinking resize can't remove excess capacity without invalidating iterators.

Use and abuse of STL vector

Posted: October 15th, 2010, 12:35 pm
by Cuchulainn
Anyone for Pool?

Use and abuse of STL vector

Posted: October 15th, 2010, 1:55 pm
by renorm
outrun,v.begin() will change as soon as the vector is relocated. Therefore shrinking resize won't relocate vector's storage.Cuchulainn,Many boost docs lack a proper tutorial. Pool is one of them. Does your books covers it?