[Bf-committers] Efficient generic data structures for Blender?

Sybren A. Stüvel sybren at stuvel.eu
Tue May 8 13:40:43 CEST 2018

Hi Christian,

On 08-05-18 13:32, Christian Hubert wrote:
> I've not found generic (template) data structures in Blender code for now. I
> mean some equivalent to std::xxx libs. Does that exist?

Much of Blender's code is written in C, so there are no templates there.
We use the BLI_ghash_xxx functions for hash maps.

> For information, what I've done so far is the following:
> *	Compared performance of std::map vs. .Net dictionaries : .Net is
> about 100x faster than std (the test populates the structure of 1000000
> integers ; 50ms for .Net vs. 5s for std, both in debug mode)

AFAIK std::map uses an ordered set as backing for the map, and not a
hash as BLI_ghash_xxx does. Not sure what .Net does.

> *	Coded an equivalent in C++, which now works for dictionary<int,
> int>: the perf is the same as the native .Net
> *	To do: need more work as it is bugged for more complex things (as
> dictionary<int, dictionary<int, bool>> crashes in my actual code due to
> memory conflicts)

I don't think it's necessary to create such data structures ourselves,
as there are many available implementations for C++ out there already
(and they are probably well tested too)

Sybren A. Stüvel


More information about the Bf-committers mailing list