Hello everyone,
As the majority of the shard scripters I store frequently accessed values which would otherwise require a massive computation or many iterations to lookup.
But I noticed that many data structures degrade their performance over the number of entries.
I wonder if a POL Developer or someone who had a chance to look at the sources could answer that. Are there any key->value data structures in pol which have a constant access time?
Thank you very much for your time.
"caching" of values
Re: "caching" of values
Escript Array is an c++ vector
Escript Dictionary is an c++ map
an vector is faster then a map especially since you need strings for map. But this is only a general statement, if you want more i need too know a escript snipet.
Escript Dictionary is an c++ map
an vector is faster then a map especially since you need strings for map. But this is only a general statement, if you want more i need too know a escript snipet.
Re: "caching" of values
Thanks a lot for your reply.
The example snippet could be:
I need the data to be accessible between scripts, so arrays and dicts would not apply (are cfgfiles implemented using C++ map too?). Do you think I should use datafile instead of global properties or maybe cfgfile? I am not sure how the above are implemented and if any of those have a constant time.
I thought about storing the lookup tables inside globals of some script or better a "method_script" of some in-game object, but the lookup for that object would probably make caching unfeasible.
The example snippet could be:
Code: Select all
// Get spell id by the name spell_name
function GetSpellId( spell_name )
spell_name := Trim( lower( spell_name ) );
var spell_id := GetGlobalProperty( "spell_id_by_name_"+spell_name );
if( not spell_id )
// do the extensive lookup through the configs in a loop
...
if( spell_id_found )
SetGlobalProperty( "spell_id_by_name_"+spell_name, spell_id_found );
else
return error{errortext:="That spell doesn't exist."};
endif
endif
return spell_id;
endfunctionI thought about storing the lookup tables inside globals of some script or better a "method_script" of some in-game object, but the lookup for that object would probably make caching unfeasible.
Re: "caching" of values
a datafile is great for storing a lot of information that shouldn't be put into globals and cfgfiles.
Re: "caching" of values
Globals, cfg and datafiles are internal basically the same a map. I would always suggest the use of datafiles. Configfiles aren't designed to modify the data. You can alter it but you never should. Globals are good but keep in mind that they are always stored during worldsave. Datafiles are only saved during a worldsave If they were altered.
Re: "caching" of values
Oh, thank you both of you. I think datafile would be my choice. I didn't know they aren't saved. The cprops were always a black box for me, so I was very cautious to use those.