views:

45

answers:

1

I've started doing my own "struct of arrays" coding, but wondered if anyone knew of libs or templates that were already out there for doing intense data transform stuff on memory constrained hardware.

I suppose what I'm looking for is a sort of "in memory" container that allows me to queue up insertions until a sync point, and mid iteration "delete". It doesn't have to be an actual delete (with the overhead of moving things around), marking as deleted would be fine too. Also, the container would probably have to be contiguous for the most part for performance sake for cache warming and such. Blocks of contiguous as opposed to completely contiguous would be fine too, but a linked list based container is just not going to cut it for memory or speed as the arrays are made of very small elements normally.

This is why I assume some kind of table class would fit, as the container would be like a table sorted by primary key.

Though well meaning, the idea of using a std::vector isn't really possible as to have something delete during an iteration would mess up the cache with accesses to the end of the array and the beginning too (count).

Also, there's no reason more than one iterator couldn't be operating on the same data, so doing something like a swap as delete would cause other iterators to skip certain elements. This is why I mention queueing up inserts.

Inserts and deletes change the shape of the container, so I'm assuming that they can be handled by a sync operation, but the action of insertion of removal could be queued during the iteration of the current contents.

+3  A: 

and mid iteration "delete". It doesn't have to be an actual delete

You can use a std::vector, but instead of erasing in the middle, you simply swap with the last element and then erase that:

#include <algorithm>

template <typename T>
void cheap_erase(std::vector<T>& vec, size_t index)
{
    using std::swap;
    swap(vec[index], vec.back());
    vec.pop_back();
}
FredOverflow
That could be `swap(vec[index], vec.back()); vec.pop_back();` to avoid messing around with iterators.
Mike Seymour
@Mike: Thanks, fixed.
FredOverflow