Earlier quoted context omitted.
Yes with the optional run-time lookup there is an extra two machine instructions (a cmp and jne) needed to check if this is the first time accessing the value. It is exactly as fast as a global variable if you don't need the optional run-time lookup. As stated in the talk, the main use case for a map like this is to cache objects which are expensive to load/compute (again something like `getFont` comes to mind). In t…
Not exactly as fast. Without -Bsymbolic, a global variabile with global symbol visibility gets its own GOT entry, meaning access to your global goes through an indirection table that supports ELF symbol interposition. (Which, IMHO, was a bad idea, but you can't unbreak an egg.) With a data structure like this (or with a conventional "struct globals"), there's one symbol at the ELF level to look up instead of one per…
C++: Associative map containers with compile-time lookup
21–30 of 45 posts
Re: C++: Associative map containers with compile-time lookup
#22Earlier quoted context omitted.
Not exactly as fast. Without -Bsymbolic, a global variabile with global symbol visibility gets its own GOT entry, meaning access to your global goes through an indirection table that supports ELF symbol interposition. (Which, IMHO, was a bad idea, but you can't unbreak an egg.) With a data structure like this (or with a conventional "struct globals"), there's one symbol at the ELF level to look up instead of one per…
Look at the approach from my other comment. Requires only 1 symbol.
Re: C++: Associative map containers with compile-time lookup
#23C++ is getting more and more like Lisp.
Re: C++: Associative map containers with compile-time lookup
#24Earlier quoted context omitted.
Yes, in a way you are right: the compiler really does boil it down to global variables. However, `semi::static_map` gives you some additional features, which may be useful for a lot of situations 1) `semi::static_map` gives you the optional run-time look-up with the same API (`semi::static_map::get`). Looking up a global variable with a runtime key isn't straight-forward. This makes it particularly nice to use an API…
Re: 3), here's a clean and technically humble way that I typically use. enum { KEY_FOO, KEY_BAR, KEY_BLAH, NUM_KEYS, }; struct KeyInfo { const char *name; int info1; float info2; }; const static struct KeyInfo keyInfo[NUM_KEYS] = { #define MAKE(x, y, z) [x] = { #x, y, z } MAKE( KEY_FOO, 1, 1.0 ), MAKE( KEY_BAR, 7, 3.5 ), MAKE( KEY_BLAH, 42, 127.2 ), #undef MAKE }; void print_key(int key) { printf("%d's name is %s\n",…
Re: C++: Associative map containers with compile-time lookup
#25C++ is getting more and more like Lisp.
Re: C++: Associative map containers with compile-time lookup
#26Re: C++: Associative map containers with compile-time lookup
#27https://issues.dlang.org/show_bug.cgi?id=1578
It's a real shame because I prefer just about everything else about metaprogramming and compile-time evaluation in D over C++.
Re: C++: Associative map containers with compile-time lookup
#28Interesting! Macro substitutions can expand to anything of course. I hadn't really considered adding lambda functions to that list.
Re: C++: Associative map containers with compile-time lookup
#29#define ID(x) []() constexpr { return x; } Interesting! Macro substitutions can expand to anything of course. I hadn't really considered adding lambda functions to that list.
Re: C++: Associative map containers with compile-time lookup
#30CppCon has super interesting content. That comes from a person who has written maybe two dozen lines of C++ code, mostly just hello world. E.g. this talk by Matt Godbolt or anything by Chadler Carruth. https://www.youtube.com/watch?v=bSkpMdDe4g4