-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why on earth are we hashing window names? #324
Comments
One benefit to the approach right now is that windows with titles can use their titles as identifiers, which is convenient (I guess). It is probably also easier for humans to pick a unique string rather than a unique integer (
There are a few problems with this approach, depending on how it is actually implemented. If it is just an incrementing counter on each call, then a simple program does not work:
Otherwise, if it is a counter that resets at the start of each frame, then this becomes a problem:
Ofc, the above might be an invalid use of that API, but it is a mistake that is easy to make, so I'm not a fan |
OK, scratch the "nk_unique_id()" :) Nevertheless, I find it irritating that we have so much fairly inefficient code (all the strlen and murmur_hash business). |
I can see your point there. Ofc, if one actually wants to be maximally efficient, Nuklear should allow the user to manage the window state themselves. Allowing one to store the state on the stack, heap, global memory, whatever they want. This also solves the "id" problem (The window state is its id), but makes the API more cumbersome to use. I think, if we want to walk down a path that changes how this id stuff works, we might as well explore ideas like this :) Anyway, not sure if this is something we can realistically change at this point (see #81, for another big MR that is kinda stuck in limbo) |
Yeah, I'm actually changing (re #81) in my own repo because all that strlen stuff makes no sense, and in my use-case I always have the string length at hand. Just for this reason. |
And just using the pointer address value of the string isn't enough? If you use whatever string in the codebase, the compiler will automatically create a global variable for that string. So you can get its address, and use it as a value to determine a unique element. |
The "name" is only used as an id for the window. So we hash it on creation of the window. Then, nk_find_window() (which is called all the time), looks for a matching window hash (recreating the hash): and then checks the name (running strlen again!).
Would it not make a whole lot more sense to say, "use a unique integer identifier" for each window (or other item that needs an id), and just store that id ... thereby not needed to do a hash nor compare strings nor do strlen just to find a window?
You could even have a "nk_unique_id()" to return, per context, a new int that is unique (just increment a counter). No need to be fancy.
What am I missing?
The text was updated successfully, but these errors were encountered: