|
Gregory McLeod
Registered User
Join date: 21 Oct 2006
Posts: 278
|
03-25-2007 03:14
Is there a way to manipulate the relative sizes of the stack and heap to give more space to one or the other? My coding is running out of space. I have shipped parts of the code to separate linked prims but this entails llMessageLinked overheads and also other event and coding requirements.
|
|
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
|
03-25-2007 07:00
In short, no. Welcome to the world the rest of us live in 
_____________________
--AeonVox--Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
|
|
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
|
03-25-2007 13:21
From: Gregory McLeod Is there a way to manipulate the relative sizes of the stack and heap to give more space to one or the other? Well, technically "yes." Write shorter bytecode and/or put less on the heap (declare fewer global variables), and you'll have more for the stack.
|
|
Fenrir Reitveld
Crazy? Don't mind if I do
Join date: 20 Apr 2005
Posts: 459
|
03-26-2007 10:39
You get 16k and that's it. Heap, code, everything has to share that. Other than breaking apart into multiple scripts, there's not much you can do other than write smaller/tighter code.
The old wiki used to have a section on this, but I'm not sure where it's located on the latest one. It had some good optimization suggestions, though, that'd save opcodes here and there (using whiles instead of for loops), or other memory management hints (like, avoiding lists, etc).
_____________________
---- ---- ----
|
|
Gregory McLeod
Registered User
Join date: 21 Oct 2006
Posts: 278
|
03-27-2007 07:32
Thanks for all the encouraging responses? I suspected that 16k was it so I am splitting further the code having optimised it as far as I could. Forunately I have many prims to spread the load over. There was a comment I read (dont know where now) that 'namespaces' could help has anyone any comments to make.
|
|
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
|
03-27-2007 07:46
From: Gregory McLeod Forunately I have many prims to spread the load over. It isn't necessary to put the scripts in separate prims. The 16k limit is per-script, not per-prim, so you can have as many scripts as you want in a single prim, each with its own compartmentalized 16k to work with. Though separating scripts among prims does have it's advantages, for example, limiting link_message cross-talk. From: someone There was a comment I read (dont know where now) that 'namespaces' could help has anyone any comments to make. LSL doesn't have namespaces, as such. The closest thing I can think of in LSL would be states, and I don't really see how either would help much with optimizing for memory efficiency.
|
|
Gregory McLeod
Registered User
Join date: 21 Oct 2006
Posts: 278
|
03-27-2007 07:53
Thanks Deanna, Firstly the 16k limit is being reached in many of my prims, so splitting the code is necessary.There are 148 prims 121 of which are similar the remaining have to handle 6 different play options each with a slightly different emphasis.
Secondly using the state does not, I think, remove the 16k limit per script OR DOES IT?
|
|
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
|
03-27-2007 08:07
From: Gregory McLeod Firstly the 16k limit is being reached in many of my prims Just to clarify, it's being reached in the scripts, though I can see how this might be confusing, since error messages only signify the prim the script is contained in, not the script itself (which in itself is an annoyance when there are multiple scripts in a prim and you're not sure which one generated the error). From: someone Secondly using the state does not, I think, remove the 16k limit per script OR DOES IT? Nothing removes the 16k per-script limit.
|
|
Ricky Lucero
Registered User
Join date: 25 Jul 2006
Posts: 122
|
03-27-2007 10:01
Are you using large lists? One thing about lists in LSL is that when you add an item to a list in standard fashion mylist += 'value' it's not adding the item to the list in the most memory efficient fashion. Instead, it's best to reset the list as you're adding an item to it mylist = (mylist=[]) + mylist + 'value' It can save quite a bit of memory if you're adding a lot of items to a list. I'll never add any item to any list without using this memory efficient way.
|
|
Gregory McLeod
Registered User
Join date: 21 Oct 2006
Posts: 278
|
03-27-2007 14:22
From: Ricky Lucero Are you using large lists? One thing about lists in LSL is that when you add an item to a list in standard fashion mylist += 'value' it's not adding the item to the list in the most memory efficient fashion. Instead, it's best to reset the list as you're adding an item to it mylist = (mylist=[]) + mylist + 'value' Well I can now post another more serious problem if you put this code in a prim the 'listen'does not seem to work. is it because of the size of the strinngs (not lists) I am using. integer CHANNEL = 42; string Adj; string Hop; integer First; integer Second; integer Third; integer Fourth; integer Fifth; integer Sixth;
integer SubStrIndx(string src,integer strt, string patrn) { string temp; integer index; integer length; integer result; length = llStringLength(src); temp = llGetSubString(src,strt,length); index = llSubStringIndex(temp,patrn); if (index == -1) result = -1; else result = index + strt; return result; }
string int2hex(integer x) { integer x0 = x & 0xF; string hexc="0123456789ABCDEF"; string res = llGetSubString(hexc, x0, x0); x = (x >> 4) & 0x0FFFFFFF; //otherwise we get infinite loop on negatives. while( x != 0 ) { x0 = x & 0xF; res = llGetSubString(hexc, x0, x0) + res; x = x >> 4; } return res; }
integer hex2int(string hex) { if(llGetSubString(hex,0,1) == "0x") return (integer)hex; if(llGetSubString(hex,0,0) == "x") return (integer)("0"+hex); return(integer)("0x"+hex); }
LoadAdj() { Adj = "020304000000030405060000040306070000"; Adj += "0503060809000603040507090704060B0000"; Adj += "080509101100090506080A110A0607090B12"; Adj += "0B070A1314000C0D190000000D0C0E191A00"; Adj += "0E0D0F1A1B000F0E101B1C0010080F111C1D"; Adj += "11080910121D12090A11131E130A0B121428"; Adj += "140B13152021151416212200161517222300"; Adj += "171618232400181724000000190C0D1A2500"; Adj += "1A0D0E191B251B0E0F1A1C261C0F101B1D27"; Adj += "1D10111C1E281E11121D1F291F12131E202A"; Adj += "2013141F212B21141520222C22151621232D"; Adj += "23161722242E241718232F0025191A263000"; Adj += "261A1B252730271B1C262831281C1D272932"; Adj += "291D1E282A332A1E1F292B342B1F202A2C35"; Adj += "2C20212B2D362D21222C2E372E22232D2F38"; Adj += "2F23242E3900302526313A0031262730323A"; Adj += "32272831333B33282932343C34292A33353D"; Adj += "352A2B34363E362B2C35373F372C2D363840"; Adj += "382D2E373941392E2F3842003A30313B4344"; Adj += "3B31323A3C443C32333B3D453D33343C3E46"; Adj += "3E34353D3F473F35363E40484036373F4149"; Adj += "41373840424A423839414B4C433A444D4E00"; Adj += "443A3B43454E453B3C44464F463C3D454750"; Adj += "473D3E464851483E3F474952493F40484A53"; Adj += "4A4041494B544B41424A4C554C424B565700"; Adj += "4D434E5859004E43444D4F594F44454E505A"; Adj += "5045464F515B51464750525C52474851535D"; Adj += "53484952545E54494A53555F554A4B545660"; Adj += "564B4C555761574C56626300584D59646500"; Adj += "594D4E585A655A4E4F595B665B4F505A5C67"; Adj += "5C50515B5D685D51525C5E695E5253000000"; Adj += "5F53545E606B6054555F616C61555660626D"; Adj += "62565761636E6357626F7000645865000000"; Adj += "65585964660066595A656700675A5B666800"; Adj += "685B5C676971695C5D686A716A5D5E696B72"; Adj += "6B5E5F6A6C736C5F606B6D746D60616C6E00"; Adj += "6E61626D6F006F62636E700070636F000000"; Adj += "716869727500726969717375736A6B727476"; Adj += "746B6C737700757171767800767273757778"; Adj += "777374767900787576797A00797677787A00"; Adj += "7A7879000000"; // llOwnerSay((string)llStringLength(Adj)); }
LoadHop() { Hop = "000000"; Hop += "02030502040703050803060A04060904070B050607050810"; Hop += "050912060911060A13070A12070B1408090A08101C08111E"; Hop += "090A0B09111D09121F0A121E0A13200B131F0B14210C0D0E"; Hop += "0C19250D0E0F0D1A260E0F100E1A250E1B270F10110F1B26"; Hop += "0F1C28101112101C27101D29111213111D28111E2A121314"; Hop += "121E29121F2B131415131F2A13202C14151614202B14212D"; Hop += "15161715212C15222E16171816222D16232F17232E18242F"; Hop += "191A1B1925301A1B1C1A26311B1C1D1B26301B27321C1D1E"; Hop += "1C27311C28331D1E1F1D28321D29341E1F201E29331E2A35"; Hop += "1F20211F2A341F2B36202122202B35202C37212223212C36"; Hop += "212D38222324222D37222E39232E38242F3925262725303A"; Hop += "26272826313B27282927313A27323C28292A28323B28333D"; Hop += "292A2B29333C29343E2A2B2C2A343D2A353F2B2C2D2B353E"; Hop += "2B36402C2D2E2C363F2C37412D2E2F2D37402D38422E3841"; Hop += "2F3942303132303A44313233313A43313B45323334323B44"; Hop += "323C46333435333C45333D47343536343D46343E48353637"; Hop += "353E47353F49363738363F4836404A37383937404937414B"; Hop += "38414A38424C39424B3A3B3C3A434D3A444F3B3C3D3B444E"; Hop += "3B45503C3D3E3C454F3C46513D3E3F3D46503D47523E3F40"; Hop += "3E47513E48533F40413F48523F4954404142404953404A55"; Hop += "414A54414B56424B55424C57434445434D58434E5A444546"; Hop += "444E59444F5B454647454F5A45505C46474846505B46515D"; Hop += "47484947515C47525E48494A48525D48535F494A4B49535E"; Hop += "4954604A4B4C4A545F4A55614B55604B56624C56614C5763"; Hop += "4D4E4F4D58644D59664E4F504E59654E5A674F50514F5A66"; Hop += "4F5B68505152505B67505C69515253515C68515D6A525354"; Hop += "525D69525E6B535455535E6A535F6C545556545F6B54606D"; Hop += "55565755606C55616E56616D56626F57626E57637058595A"; Hop += "595A5B5A5B5C5B5C5D5B68715C5D5E5D69715D6A735E5F60"; Hop += "5E6A725E6B745F60615F6B73606162606C74616263646566"; Hop += "65666766676867686968696A687175696A6B6972766A6B6C"; Hop += "6A72756A73776B6C6D6B73766C6D6E6C74776D6C6B6D6E6F"; Hop += "6E6F70717273717578727374727679737678747779757677"; Hop += "75787A77797A"; // llOwnerSay((string)llStringLength(Hop)); }
GetAdjValues(string Origin) { string temp; integer index = 0; do { index = SubStrIndx(Adj,index,Origin); llOwnerSay((string)index); if ((index % 12) == 0) { temp = llGetSubString(Adj,index,index + 12); llOwnerSay(temp); jump out1; } else { llOwnerSay("error"); ++index; } } while(index < 1440); @out1; First = hex2int(llGetSubString(temp,2,3)); Second = hex2int(llGetSubString(temp,4,5)); Third = hex2int(llGetSubString(temp,6,7)); // Fourth = llGetSubString(temp,12,14); // Fifth = llGetSubString(temp,15,17); // Sixth = llGetSubString(temp,18,20); // Values = First + "," + Second + "," + Third + "," + Fourth + "," + Fifth + "," + Sixth; // llOwnerSay(Values); }
GetHopValues(string Origin, string Blocking) { integer index; integer tindx; string temp; string subHop; index = SubStrIndx(Hop,0,Origin + Blocking); llOwnerSay((string)index); llOwnerSay((string)(index % 6)); if (index > 0) { if ((index % 6) == 0) { temp = llGetSubString(Hop,(index + 4),(index + 5)); llOwnerSay(temp); jump out1; } else { do { llOwnerSay("Do"); // subHop = llGetSubString(Hop, index + 1, 1602); // llOwnerSay((string)llStringLength(subHop)); index = SubStrIndx(Hop,index + 1,Origin + Blocking); llOwnerSay((string)index); llOwnerSay((string)(index % 6)); if ((index % 6) == 0) { temp = llGetSubString(Hop,(index + 4),(index + 5)); llOwnerSay(temp); jump out2; } } while (index < 1596); } @out1; @out2; } else { llOwnerSay("Second part"); index = SubStrIndx(Hop,0,Blocking + Origin); llOwnerSay((string)index); if (index > 0) { if((index % 6) == 2) { temp = llGetSubString(Hop,(index - 2),(index - 1)); llOwnerSay(temp); jump out3; } } else { do { // subHop = llGetSubString(Hop, index + 1, 1602); llOwnerSay((string)index); llOwnerSay((string)(index % 6)); index = SubStrIndx(Hop,index + 1,Blocking + Origin); if ((index % 6) == 2) { temp = llGetSubString(Hop,(index - 2),(index - 1)); llOwnerSay(temp); jump out4; } } while (index < 1600); } @out3; @out4; } // llOwnerSay(temp); }
default { state_entry() { LoadAdj(); llOwnerSay("Adj loaded"); LoadHop(); llOwnerSay("Hop loaded"); } touch_start(integer total_number) { llOwnerSay((string)llGetFreeMemory()); }
listen(integer CHANNEL, string name, key id, string message) { if(message == "Memory") { llOwnerSay((string)llGetFreeMemory()); } else if(llGetSubString(message,0,4) == "Test1") { string tester = int2hex((integer)llGetSubString(message,5,7)); llOwnerSay(tester); GetAdjValues(tester); // llOwnerSay(First); // llOwnerSay(Second); // llOwnerSay(Third); // llOwnerSay(Fourth); // llOwnerSay(Fifth); // llOwnerSay(Sixth);
} else if(llGetSubString(message,0,4) == "Test2") { string tester1 = llGetSubString(message,5,7); string tester2 = llGetSubString(message,8,10); llOwnerSay("Start"); llOwnerSay(tester1 + " " + tester2); // integer inum1 = hex2int(tester1); // llOwnerSay((string)inum1); // integer inum2 = hex2int(tester2); // llOwnerSay((string)inum2); // string hnum1 = int2hex((integer)tester1); // llOwnerSay(hnum1); // string hnum2 = int2hex((integer)tester2); // llOwnerSay(hnum2); // hnum1 = // GetHopValues(hnum1,hnum2); // llOwnerSay((string)temp); } } }
if you do can you tell me why it doesnt work.
|
|
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
|
03-27-2007 14:52
I don't see an llListen anywhere... you forgot to set up the listen?
|
|
Gregory McLeod
Registered User
Join date: 21 Oct 2006
Posts: 278
|
03-28-2007 01:05
DUH! You are absolutely right. Thats what comes of trying to put together parts of other scripts. Thanks
|