On Wed, 13 Jun 2012, Kirk, Benjamin (JSC-EG311) wrote: >> On the other hand I was thinking that the sorting feature of the set isn't >> a bad thing because you're going to loop over them calling set() on the >> numeric vector... so having them in order might things more efficient >> (memory access wise)... but I'm sure that doesn't play out in reality and >> I'm just trying to justify my inefficient but simple algorithm ;-) > > Maybe. I like Roy's suggestion though, and importnantly it is also more > memory efficient.
True. I think a set<int> takes up about 3 times the space of a vector<int> that's been preallocated to the same size. Up that to 4 times the space if you need to copy the set into a vector anyway to hand off to an API expecting a vector or array. But then cut that down by some significant but unknown factor unless your vector-based user code does two passes, with the first to figure out how much space to reserve(). If you just push_back() then your STL implementation will try to save you a bunch of CPU time at the cost of memory by doing reallocations with increasingly large chunks of spare overhead. --- Roy ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Libmesh-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libmesh-users
