Script memory

Thinking about script memory in LSL is very important.  In Mono, which is the modern script engine, each script gets 64K of memory allocated by default.  This is true even if the script uses only a few kilobytes of memory.

With thousands of scripts in a region, this can easily consume all the memory allocated to the region, and cause the region to start swapping memory out to disk (this all happens at the Linden Lab server running the region).  Swapping is a Bad Thing™ and will drastically slow down the sim, which you’ll see as lag.

So, what as script creators can we do?  If you have a script that takes no external input, you can limit the amount of memory your script will be allocated with a llSetMemoryLimit () function call.

Firstly, what do I mean by “takes no external input”?  An example of something that takes external input is something like a picture frame that displays the owner’s selection of textures.  The owner can drag textures into the frame and display them.  Typically to do this, the script will load the names of the textures into a list, and therefore the amount of memory used by the list is out of the control of the script creator.  It depends on how many textures the owner loads into the frame’s contents, and not how the script creator codes the script.

So, if you have something that doesn’t allocate memory out of your control, how do you know what upper limit to set with your call to llSetMemoryLimit ()?  There’s a set of memory profiling calls that will tell you.  And, as you may have guessed, this post was prompted by someone triggering the swapping problem on my home sim, which made me see if I could drop the memory that my scripts allocate.

To make things easy, I created an include file for my scripts.  Let me show you an example of how I use it.  You can access the included files by following the link in the comments next to them.

#define DEBUG
#include "debug.lsl"      // See the source of debug.lsl

#define MEMLIMIT 8000
#define PROFILE
#include "profile.lsl"    // See the source of profile.lsl

#define BLUE "c3623b1f-db83-4003-bb6d-d0d60d32c621"

phantom (integer p) {
    llSetLinkPrimitiveParamsFast (LINK_THIS, [PRIM_PHANTOM, p]);
}

default {
    state_entry () {
        init_profile ();
        llCollisionFilter ("", BLUE, TRUE);
        phantom (FALSE);
    }

    collision_start (integer n) {
        phantom (TRUE);
        llSetTimerEvent (2.0);
    }
    
    timer () {
        llSetTimerEvent (0.0);
        phantom (FALSE);
        show_profile ("timer");
    }
}

This is a simple script that goes in an invisible barrier.  It lets me walk through it by turning the barrier phantom when I collide with it, but for everyone else, it does nothing.  It takes no external input, all the memory it will use is its code, it doesn’t even use any variables!  So this is a perfect candidate for limiting script memory allocation.

The code at the top includes my standard debugging code, and the

#define MEMLIMIT 8000
#define PROFILE
#include "profile.lsl"

defines an initial memory limit of 8000 bytes, tells profile.lsl to enable profiling, and includes the profiling code.

Now notice the calls to init_profile () and show_profile ().  The init_profile () call sets the script’s memory limit based on the MEMLIMIT definition, and starts memory profiling if PROFILE is defined (and, just a warning here, memory profiling can drastically slow down your script so make sure you turn it off when done!)

The show_profile () call displays the current maximum amount of memory the script has used.  It can be tricky to figure out where to put this call, but in this case, it’s easy, as the script flow first sets everything up and then waits for a collision by me, followed by the timer firing.  So the logical place to put the show_profile () call is at the end of the timer.  All the code has run by this stage.

When you save this, and collide with it (if you’re trying this, don’t forget to replace my UUID with yours!), you’ll see something similar to the following…

Barrier: Memory profile init: 0
Barrier: Memory profile show (timer): 7598

This tells us that at the end of the timer event, the most memory the script has ever used is 7598 bytes, so our starting figure of 8000 was close.  If you see

Barrier: MEMLIMIT = 8000 too small

increase the size of MEMLIMIT until this message goes away.

I will leave a little buffer between the size reported and the limit, just in case 🙂  So in my example, I left MEMLIMIT at 8000.  Doing this simple exercise saved over 56K!  That may not sound like a lot, but don’t forget there can be thousands of scripts running in a region, so it adds up.

Once you’ve figured out a good number for MEMLIMIT, don’t forget to turn off debugging and profiling by changing the #define DEBUG and #define PROFILE to #undef DEBUG and #undef PROFILE, and leave the init_profile () and show_profile () calls in place.  The init_profile () call just sets the memory limit when PROFILE is undefined (and the show_profile () call is replaced by a blank line of code).

If every script creator did this, we’d be living much less laggy second lives!


Dandelions

This is another hunt item from the Womenstuff Hunt.  Although the motto is a bit risqué in some parts of the world, I love the dandelion motif.

This sweater dress is pretty short, so if you want to keep warm, add some tights 🙂  It comes in sizes for Lara, Venus, Isis, Freya, Hourglass, Physique, Curvy, Fine, and standard mesh sizes for classic avatars.

It has a HUD system with eight presets, but it also has a universal color picker so you can tint the dress, ties, and grommets any color your choose.


Twilight glow

Aloha kākou!  Hello, my friends!  The Snow Queen awaits you at the latest round of Enchantment, open now until December 2.  I wanted to share the beautiful gown from Silvan Moon Designs, Crystallis.

I usually shy away from pinks and corals — they often clash with my ginger — but I saw Bee’s colours in the Amaryllis style for Crystallis and I just fell in love.  I feel like I’m dressed in the sunset.

  • <K&S> — Loveliness #4 pose

I don’t get enough opportunity to wear the Springleaf necklace from Empyrean Forge — it’s a large piece, and definitely requires a strapless gown — or at least a broad expanse of chest — so that it’s not crowded.  It works perfectly with the Crystallis gown.

I wish you all a wonderful weekend!  If you are able, recharge, rejuvenate, refill with peace and strength for the week ahead.  If you are not able, find some time to breathe and take in a little peace…  and that rejuvenation time will come.

Mahalo!  A hui hou kākou!

Pictures were taken on a private sim.

I am wearing:


VIP

Another item from the Womenstuff Hunt today.  The hunt goes until the end of the month, so there’s plenty of time to find all the outfits.

This looks to be experimental Lara, and there is Physique, Hourglass, Venus, and standard sizes as well.  The strapped pumps are included, as well as a handbag (not shown).

The rigging is only just there, and I certainly needed to use plenty of alpha to hide bits.  However, it’s a nice classy outfit for going out shopping or something 🙂


Cozy time

Here’s another fab outfit from the Womenstuff Hunt.  It’s certainly been a great hunt this time around for clothes!

This cable knit sweater dress comes in sizes for Lara, Freya, Isis, Venus, Hourglass, Physique, Ocacim, Curvy, Fine, and two sizes for classic avatars.  There are two colors of tights, Cocoa (shown) and plum, and they come on system layers (yay, designers are thinking about BoM!) and Omega appliers.  And the boots are fitted for Maitreya, Slink, Belleza, and standard avatars.

The heap collar on this gave me no end of trouble finding a hairstyle that would suit.  I finally went for an old standby that I haven’t worn for ages 🙂


Leila

I enjoy it when the Womenstuff Hunt is on, I know I’m going to have something to show you every day without completely running around and looking too hard lol

This knit dress comes in sizes for Lara, Freya, Venus, Isis, eBody, Hourglass, Physique, Curvy, and Fine.  It has a 16 color HUD to color the dress and collar separately.  The texture could be finer, but it’s a very nice hunt item just the same!


Unity

Here’s a more daring outfit from the Womenstuff Hunt, this time from Vaxer.

This outfit, including the stocking and chains, is all one piece for Lara, Hourglass, and Physique.  There’s a ten color HUD included too, so you can find a color scheme that suits!

There’s some really nice detail in the metal parts, and the fit is excellent.  Another fine hunt item from a great creator!


Basic animation chooser

Sometimes, you just need something simple to pick an animation to play.  Here’s a script to do just that.  Rez a prim, drop this script in it, and a bunch of animations, then take and wear it as a HUD.

When you touch it, it will offer you a dialog where you can play any of the animations, or stop the one currently playing.

Note the links to the included scripts.  If you don’t use the Firestorm preprocessor, you can get the source for the #included bits by following the link in the comment next to the #include.  Just cut and paste the code into the top of this script, replacing the #include.

#include "dialog_plus.lsl"  // see the source of dialog_plus.lsl
#include "privchan.lsl"     // see the source of privchan.lsl

integer g_have_perms;
string g_current;
list g_animations;
key g_owner;
integer g_channel;
integer g_listen_handle;
string g_msg = "Select";

default {
    
    attach (key id) {
        if (id != NULL_KEY) {
            llResetScript ();
        } else {
            if (g_have_perms && g_current != "") {
                llStopAnimation (g_current);
            }
        }
    }

    state_entry () {
        integer n = llGetInventoryNumber (INVENTORY_ANIMATION);
        integer i;
        string name;
        g_current = "";
        g_animations = ["Stop"];
        g_have_perms = FALSE;
        g_owner = llGetOwner ();
        g_channel = privchan ();
        for (i = 0; i < n; i++) { 
            name = llGetInventoryName (INVENTORY_ANIMATION, i);
            if (llStringLength (name) > 24) {
                llOwnerSay ("Animation \"" + name + "\" longer than 24 chars, not loaded");
            } else {
                g_animations += name;
            }
        }
        llRequestPermissions (g_owner, PERMISSION_TRIGGER_ANIMATION);
    }
            
    run_time_permissions (integer p) {
        if (p & PERMISSION_TRIGGER_ANIMATION) {
            g_have_perms = TRUE;
        }
    }
    
    touch_start(integer total_number) {
        llListenRemove (g_listen_handle);
        g_listen_handle = llListen (g_channel, "", g_owner, "");
        DialogPlus (g_owner, g_msg, g_animations, g_channel, g_menu_idx = 0);
    }

    listen (integer chan, string name, key id, string data) {
        if (chan == g_channel) {
            if (data == "Back") {
                DialogPlus (g_owner, g_msg, g_animations, g_channel, --g_menu_idx);
            } else if (data == "Next") {
                DialogPlus (g_owner, g_msg, g_animations, g_channel, ++g_menu_idx);
            } else if (data == "Stop") {
                if (g_current != "" && g_have_perms) {
                    llListenRemove (g_listen_handle);
                    llStopAnimation (g_current);
                    g_current = "";
                }
            } else {
                if (g_have_perms) {
                    llListenRemove (g_listen_handle);
                    if (g_current != "") {
                        llStopAnimation (g_current);
                    }
                    g_current = data;
                    llStartAnimation (g_current);
                }
            }
        }
    }
}

Lovie

Hello, lovelies!  I have another pretty dress to show you from the Womenstuff Hunt today!

This dress is original mesh from Gaall, and it only comes in sizes for Lara, Physique, and Hourglass, but if you have one of those, you’re in luck, because it’s a very nice dress.  It’s a tiny bit translucent, just enough to tease when the sun shines though it 🙂

It also comes with an 18 color HUD, where you can pick from black, white, and 16 light pastels.  A very nice hunt item!


Night lights

Aloha kākou!  Happy Friday, everyone!  I was thinking about going out dancing tonight, so I thought I’d share a wonderful little outfit and skin with you!  The outfit is a little mix-and-match from R2 Fashion A/D/E, and the Psy skin is from Fallen Gods.

  • <K&S> — Loveliness #3 pose

I’m always amazed at what the creators in SL can do with textures and materials these days.  The shine on the R2 outfits is incredible — from the metallic sheen to the gloss on the transparent bits.

  • StardustSummer Breeze 05 Bento Pose

I really love the Psy series of skins that Alia at Fallen Gods has created.  The electricity/plasma/lightning-y patterns on the dark skin really lend themselves to my creativity.

  • StardustSummer Breeze 03 Bento Pose

Sometimes you just need to dress how you feel…. and sometimes you need to feel how you dress.  So, you know — it’s Friday… time to feel sparkly.

Have a wonderfully happy weekend, my friends!  A hui hou kākou!

Pictures were taken at Backdrop City and at INSILICO

I am wearing: