• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

question about structs

Status
Not open for further replies.
Level 3
Joined
Nov 8, 2009
Messages
39
Hypothetically speaking, when passing 2 or more values through to a simple timer handler, would I be better off using a struct over a hashtable? How about 3 or more? I guess I'm curious how intensive the initialization of the struct itself is, and when it becomes worthwhile to use them vs. a hashtable while performing smallish tasks. I'm using a custom allocator (thanks to Nestharus' awesome video tutorial :thumbs_up:) and timerutils in array storage mode if that helps.

Presently, I've been going back through some of my older code, and kinda just eyeballing to see if there are tons of hashtable reads/writes being made. In some cases it's pretty obvious, and I love the way that structs streamline those systems, but with the more borderline scenarios described above, it's a lot less clear if making the transition will be worthwhile.
 
Level 7
Joined
Nov 15, 2009
Messages
225
It depends on what you want to do.

Structs (those which doesn't extend array) have a good and fast and easy indexing.
But for just 2 or 3 variables I would prefer using hashtables.
It's faster to write and you use less lines of code, which is easier to read for anyone else but you.

Structs show their real advantage with some more variables or if you want an eye-candy code. ;)
 
Level 3
Joined
Nov 8, 2009
Messages
39
Cool, that's pretty much the way I've been approaching things so far. :wink:

You mention however, that structs which don't extend array are fast. Did you mean to imply that those which do are measurably slower? I was under the impression that it's ideal to extend the array and use an allocator module.
 
The wording is a bit weird. However, he just means that the ones that don't extend arrays have a built-in indexing that performs quickly and easily. If you use a custom allocator, it is fast and easy as well.

As for the debate between structs versus hashtables, when it gets down to 2 or 3 variables, it is really just a matter of personal preference. You can use whichever one you feel like using.

Indexing is normally faster. However, comparing the speeds is like comparing apples to apples. I personally use indexing because I feel like hashtables are clunky. But in such small situations, I sometimes will try to find a way to avoid using indexing.
 
Level 3
Joined
Nov 8, 2009
Messages
39
Thanks, that really helps to clear things up. Since I'm mostly revamping old code, it seems to make sense to reserve the struct retrofits for the more intensive hashtable-based systems, as I've been doing. If I was starting from scratch though, I'd definitely be using structs, as they're so much easier to read at a glance! +Rep to both of you for the helpful responses!
 
Status
Not open for further replies.
Top