Skip to main content
added 372 characters in body
Source Link
Liuka
  • 585
  • 2
  • 4
  • 19

In my project I use hashed strings, which are transformed, at compile time in unique (I wish!) numbers. So, when I need a resource, for example a texture I simply call

MngTexture->get(hash("my_texture"))

And since I'm creating a simple entity system framework and I need to load components data from files I created a simple language like json to store data, but is compilable (transforming words and chars from digits to number and from strings to hashed values). So, for example, if I want to link the texture with ID hash("my_texture") to "ball.PNG" in my data file I'll have

|my_texture| = "ball.PNG"

Where || is an operator which tells the compiler to hash the word inside.

So basically I use strings which are mapped to ints at compile time (so they haven't any overhead), both in the actual code and in the files which are the streams for loading components. For computing the hash a compile time simply google it, it a simple function of 5-10 lines of code.

Of course you can load the string from you're files and hashes it at run time, in this case you don't have to write the dictionary on your own because the algorithm will do it for you (creating integers from strings) and I think hasing is at least as fast as searching in a map, because of memory locality (you are just looping through a string which is few bytes long).

Hope this can help.

In my project I use hashed strings, which are transformed, at compile time in unique (I wish!) numbers. So, when I need a resource, for example a texture I simply call

MngTexture->get(hash("my_texture"))

And since I'm creating a simple entity system framework and I need to load components data from files I created a simple language like json to store data, but is compilable (transforming words and chars from digits to number and from strings to hashed values). So, for example, if I want to link the texture with ID hash("my_texture") to "ball.PNG" in my data file I'll have

|my_texture| = "ball.PNG"

Where || is an operator which tells the compiler to hash the word inside.

So basically I use strings which are mapped to ints at compile time (so they haven't any overhead), both in the actual code and in the files which are the streams for loading components. For computing the hash a compile time simply google it, it a simple function of 5-10 lines of code.

Hope this can help.

In my project I use hashed strings, which are transformed, at compile time in unique (I wish!) numbers. So, when I need a resource, for example a texture I simply call

MngTexture->get(hash("my_texture"))

And since I'm creating a simple entity system framework and I need to load components data from files I created a simple language like json to store data, but is compilable (transforming words and chars from digits to number and from strings to hashed values). So, for example, if I want to link the texture with ID hash("my_texture") to "ball.PNG" in my data file I'll have

|my_texture| = "ball.PNG"

Where || is an operator which tells the compiler to hash the word inside.

So basically I use strings which are mapped to ints at compile time (so they haven't any overhead), both in the actual code and in the files which are the streams for loading components. For computing the hash a compile time simply google it, it a simple function of 5-10 lines of code.

Of course you can load the string from you're files and hashes it at run time, in this case you don't have to write the dictionary on your own because the algorithm will do it for you (creating integers from strings) and I think hasing is at least as fast as searching in a map, because of memory locality (you are just looping through a string which is few bytes long).

Hope this can help.

Source Link
Liuka
  • 585
  • 2
  • 4
  • 19

In my project I use hashed strings, which are transformed, at compile time in unique (I wish!) numbers. So, when I need a resource, for example a texture I simply call

MngTexture->get(hash("my_texture"))

And since I'm creating a simple entity system framework and I need to load components data from files I created a simple language like json to store data, but is compilable (transforming words and chars from digits to number and from strings to hashed values). So, for example, if I want to link the texture with ID hash("my_texture") to "ball.PNG" in my data file I'll have

|my_texture| = "ball.PNG"

Where || is an operator which tells the compiler to hash the word inside.

So basically I use strings which are mapped to ints at compile time (so they haven't any overhead), both in the actual code and in the files which are the streams for loading components. For computing the hash a compile time simply google it, it a simple function of 5-10 lines of code.

Hope this can help.