Jump to content

Remedial scripting: Need Mono memory trick


Qie Niangao
 Share

You are about to reply to a thread that has been inactive for 4774 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Somehow I haven't had occasion to worry about this since Mono, but I'm now trying to squeeze as many characters as possible into a string.  I realize I have no idea how to do it any more.

In LSO, we'd use an embedded empty assignment, as in the following example:

 

string myString;
integer CEILING = 2000;
string dummyText = "The quick brown fox jumped over the lazy dog.  Now is the time for all good men to come to the aid of the party.\n";

default
{
    state_entry()
    {
        llOwnerSay("Free mem = "+(string)llGetFreeMemory()
                +"; strLen = "+(string) llStringLength(myString));
        while(CEILING < llGetFreeMemory())
            //myString += dummyText;
            myString = (myString = "") + myString + dummyText;
        llOwnerSay("Free mem = "+(string)llGetFreeMemory()
                +"; strLen = "+(string) llStringLength(myString));
    }
}

Compiled as LSO, that dutifully gobbles up most of the script's original 15753 free memory into the string.  In Mono, it has to stop just shy of half the original 60882 free mem, and behaves exactly the same as the straight "+=" assignment.  I knew that trick didn't work in Mono, but what is to be done instead, to avoid leaving the whole intermediate string on the stack when making an assignment in Mono?

ETA:  Oh crap.  Looking at a jira, it appears that Mono uses UTF-16 encoding for strings (and even UUIDs !?!), which I'd ruled out as being simply too silly to consider.  Taking that into account, it seems it's not that stuff is getting stranded on the stack, it's that stuff is just twice as big as it has any reason to be. So... sorry for the distraction.

 

Link to comment
Share on other sites

Thanks Cerise.  That wiki article has a nice clear explanation of how to compress text for storage.  Unfortunately, however, I'm trying to cons up an actual string to pass to llHTTPResponse(), so even if I compressed the text for storage I'd have to uncompress it all at once to pass into that function.  So I'm screwed, but it's still a good technique to have handy.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4774 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...