c++ – Using strings to identify objects: whats the purpose?

c++ – Using strings to identify objects: whats the purpose?

Yes, it would be faster to use plain variable names in code instead of using string identifiers. But sometimes you dont know those names during build-time. Then you need an approach to handle names dynamically. An alternative approach could be to just use primitive integers instead of strings. The integer values could possibly be generated using a hash or a lookup table of strings. But using strings wouldnt violently slow down your program, unless you have a lot of strings of very huge length which all have the same starting characters and only have a few different characters at the end. Normally, comparing strings should lead to a false result relatively early and only for the true match it is necessary to compare the two strings completely. However, the comparison of some strings to find objects within a well-organized search structure (like trees etc.) is not the bottleneck of 3D engines and, thus, should not be part of optimization issues

Well I got the answer by a teacher:

In fact a string identifier, once in a map thus inserted in order, is quickly found with a dichotomic search.

c++ – Using strings to identify objects: whats the purpose?

Leave a Reply

Your email address will not be published. Required fields are marked *