cprogrammer
cprogrammer

Reputation: 5675

Boost.Flyweight memory consumption

I'm just reading an article about Boost.Flyweight Performance

As you can see in the link the overhead of the factory is
- for hashed_factory: ~2.5 * sizeof(word)
- for set_factory: 4 * sizeof(word)

The basic question is .... why 4 words for set and not zero ?

As far as I know, using a hash implies computing and storing a hash key, while using a set not: it's implemented as a red-black-tree, inserting and look-up takes log(n), so no values is stored and memory overhead should be zero (with the drawback that instead of one comparison in the case of hash you will have log(n) comparisons). Where is the mistake ?

Upvotes: 1

Views: 503

Answers (1)

jpalecek
jpalecek

Reputation: 47770

Each node of the RB tree contains a pointer to the left child, pointer to the right child, the color and one piece of data. The first three count as overhead, which means it isn't 0. I'm not quite sure why they say it's 4 when the 3 elements fit easily in 3 words, but maybe they count in something else (like the parent node pointer, which isn't strictly necessary, or memory allocation overhead, although that's unlikely).

Upvotes: 1

Related Questions