开发者

Is there any Tables lib/code for in memory manipulation in C++ [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.

Closed 8 years ago.

Improve this question

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开发者_Python百科 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.


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();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜