Don't string me!

Post » Fri Aug 26, 2011 6:01 pm

Hello @ll,

just another curious question I have.

Being used to String handling like in Java and other languages delivering cool copy constructors,
I am a bit overwhelmed by the CS/OBSE string handling. (totally forgot about my c times there...)
The question:
Assuming sv_Destruct really gets rid of the String the (String)-Variable XYZ was assigned to,
do I have to make a difference between constructed strings and string literals.

All I know for string literals reside in memory as long as the program is running.
Calling sv_Destruct on String Variable XYZ, which has been assigned a string literal,
should only zero the string variable XYZ. (string points to zero ref)
But calling sv_Destruct on String Variable XYZ, which has been assigned a temporary string build with sv_Construct,
should delete the string completely. (string points to zero ref and memory is deallocated)

Now my thought was, every time I do assign a new constructed string with sv_Construct to String Variable XYZ,
I should call sv_Destruct on String Variable XYZ first, in order to dealloccate the memory from the previously
assigned string, which was assigned by sc_Construct too ( meaning it was no string literal)

Ok, thanks for any help here.
I really dont want to bloat anyones savegame, so this question might sound stupid, but im in lack of knowledge here, which isnt even available in OBSE docs. :toughninja:
User avatar
Matt Gammond
 
Posts: 3410
Joined: Mon Jul 02, 2007 2:38 pm

Post » Sat Aug 27, 2011 6:57 am

You only need to call sv_destruct on the variable name. So given string_var myString, sv_destruct myString will take care of it when you're done with it and no bloating will occur.
User avatar
Marquis T
 
Posts: 3425
Joined: Fri Aug 31, 2007 4:39 pm

Post » Fri Aug 26, 2011 10:21 pm

Now my thought was, every time I do assign a new constructed string with sv_Construct to String Variable XYZ,
I should call sv_Destruct on String Variable XYZ first, in order to dealloccate the memory from the previously
assigned string, which was assigned by sc_Construct too ( meaning it was no string literal)
No, this is not necessary, when you assign something to a string_var, the previously assigned string gets freed automatically. I do al to of string handling where string variables numerous times, even in loops. And no bloat is created by that - unlike the cases where I forgot to call sv_Construct before exiting user-defined functions, making the string_var cause one line of bloat in the savegame for every call to the function!
User avatar
Tamika Jett
 
Posts: 3301
Joined: Wed Jun 06, 2007 3:44 am

Post » Fri Aug 26, 2011 10:47 pm

No, this is not necessary, when you assign something to a string_var, the previously assigned string gets freed automatically. I do al to of string handling where string variables numerous times, even in loops. And no bloat is created by that - unlike the cases where I forgot to call sv_Construct before exiting user-defined functions, making the string_var cause one line of bloat in the savegame for every call to the function!


Thank you very much, the only question was the save game bloat, anyway, since we don not really know how heap & memory management is working,
it is better to assume its done automatically by some kind of garbage function.
In order to really know, I could write a script reassigning massive string variables in such way

let str_var_a := sv_Contruct "%z" str_var_b

and dont use sv_Destruct on str_var_a before. :spotted owl:
User avatar
Matthew Aaron Evans
 
Posts: 3361
Joined: Wed Jul 25, 2007 2:59 am


Return to IV - Oblivion