Page 1 of 1
"caching" of values
Posted: Sat Feb 05, 2011 9:54 am
by andenixa
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.
Re: "caching" of values
Posted: Sat Feb 05, 2011 4:12 pm
by Turley
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.
Re: "caching" of values
Posted: Wed Feb 09, 2011 6:07 pm
by andenixa
Thanks a lot for your reply.
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;
endfunction
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.
Re: "caching" of values
Posted: Sat Feb 12, 2011 3:17 am
by CWO
a datafile is great for storing a lot of information that shouldn't be put into globals and cfgfiles.
Re: "caching" of values
Posted: Sat Feb 12, 2011 7:27 am
by Turley
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
Posted: Sun Feb 13, 2011 7:25 am
by andenixa
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.