|
Neo Codesmith
Registered User
Join date: 25 Dec 2004
Posts: 10
|
02-22-2006 15:14
I have been trying to get my rpg game code safely under 16k and noticed the memory was really getting sucked up in the listen event. So I did some testing and found that 2 floats were using 10 bytes per float more in the touch_start event than they were as globals! Then I tried a 50 char string and it took up 52 bytes more as a local variable than if it was a global string. I also tried making the string zero length after using it but that did nothing.
Do we switch to only using globals? lol
-Neo
|
|
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
|
02-22-2006 15:36
I believe what you're seeing is the small overhead of using the stack or the heap to allocate variables.
Perhaps you should go over your code, and find lists that are unnecessary or could be reduced?
|
|
Neo Codesmith
Registered User
Join date: 25 Dec 2004
Posts: 10
|
02-22-2006 22:20
Overhead is expected but this seems to be more than that. With all the string passing we're forced to do between scripts it's pretty scary to think the string size could be doubling. If there was a garbage collector this probably wouldn't be a problem but I don't think lsl has one.
But yah I've already trimmed a lot of fat, I just noticed the memory use can creep back up real fast inside events.
|
|
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
|
02-23-2006 10:41
As to the string thing, if you're doing this:
string foo = "abcdef";
then you lose the space for "abcdef" twice: once in the compiled code and once at runtime. That is, you would expect the variable to take up space once, while the code is running, to store the value, but the string initialization value itself also has to come from somewhere, and that is in the script's bytecode.
Then again, I'd expect to see that with a global variable too, so maybe that's not what's going on here.
|
|
Harris Hare
Second Life Resident
Join date: 5 Nov 2004
Posts: 301
|
02-23-2006 11:16
Are you saying that: string foo; foo = "abcdef"; ... is better than ... string foo = "abcdef"; .. or are you guys talking on a level above me? 
|
|
Neo Codesmith
Registered User
Join date: 25 Dec 2004
Posts: 10
|
02-24-2006 00:29
From: Harris Hare Are you saying that: string foo; foo = "abcdef"; ... is better than ... string foo = "abcdef"; .. or are you guys talking on a level above me?  Nope wasn't talking about that. I'm not sure if there is any difference in lsl but I like to initialize variables when possible string foo = "abcdef"; I was talking about memory use when you declare variables inside of an event like touch_start instead of in a function or as a global variable. I've got the memory under control now so I guess it's all good.
|
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
02-24-2006 07:05
From: Harris Hare Are you saying that: string foo; foo = "abcdef"; ... is better than ... string foo = "abcdef"; .. or are you guys talking on a level above me?  string foo; foo = "abcdef"; is worse then string foo = "abcdef"; globals will use up less space because they don't have to be allocated and deallocated from the stack. I cannot explain your 52 byte difference without looking at your code. You will find my thread on script optimization interest to read.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
|
Neo Codesmith
Registered User
Join date: 25 Dec 2004
Posts: 10
|
02-24-2006 14:22
//string s = "01234567890123456789012345678901234567890123456789";
default { state_entry() {
}
touch_start(integer total_number) { string s = "01234567890123456789012345678901234567890123456789"; llSay(0, (string)llGetFreeMemory()); } }
Running this I get 16,063 for global and 16,011 for in the event.
|