llSetMemoryLimit

From Second Life Wiki
Revision as of 23:58, 18 August 2011 by Pauline Darkfury (talk | contribs) (Removed the pre-release status, added a note about real memory used vs. upper limit for Mono.)
Jump to navigation Jump to search

Summary

Function: integer llSetMemoryLimit( integer limit );

Request limit bytes to be reserved for this script.
Returns the integer Success/Failure Flag for whether the memory limit was set.

• integer limit

Specification

This function's behavior is dependent upon the VM the script is using. Mono is the new VM, LSO is the old VM.

Mono
Sets the memory limit for the script.
  • The memory limit can be set up to 64k.
  • The memory limit can not be set lower than the memory currently in use by the script.
  • All new scripts start with a limit of 64k
  • All existing scripts have a limit of 64k
  • A lower limit will effect the amount of memory reported in the viewer UI and by llGetObjectDetails.
  • The memory limit is not the amount of real memory actually used by the script, just the upper limit on it.
LSO
Has no effect on LSO scripts which will always use exactly 16k

Success/Failure Flags Description
STATUS_OK 0 Result of function call was success
STATUS_MALFORMED_PARAMS 1000 Function was called with malformed parameters
STATUS_TYPE_MISMATCH 1001 Argument(s) passed to function had a type mismatch
STATUS_BOUNDS_ERROR 1002 Argument(s) passed to function had a bounds error
STATUS_NOT_FOUND 1003 Object or other item was not found
STATUS_NOT_SUPPORTED 1004 Feature not supported
STATUS_INTERNAL_ERROR 1999 An internal error occurred
STATUS_WHITELIST_FAILED 2001 Whitelist Failed

Examples

<lsl> // Memory-walkthrough by Daemonika Nightfire (daemonika.nightfire)

integer limit = 20000; // <- bytes

Test() {

   llSetText("Limited Memory " + (string)llGetMemoryLimit() +
             "\nUsed Memory " + (string)llGetUsedMemory() +
             "\nFree Memory " + (string)llGetFreeMemory(),<1,1,1>,1);

}

default {

   state_entry()
   {
       llSetMemoryLimit(limit);
       
       llScriptProfiler(PROFILE_SCRIPT_MEMORY);
       Test();
       llScriptProfiler(PROFILE_NONE);
       
       llSay(0,"This script used at most " + (string)llGetSPMaxMemory() + " bytes of memory during Test.");
   }

}

// Result:

// Floating Text: // Limited Memory 20000 // Used Memory 4972 // Free Memory 15100

// Chat: // [05:11] Object: This script used at most 4972 bytes of memory during Test.

</lsl>

See Also

Functions

•  llGetFreeMemory
•  llGetUsedMemory
•  llGetObjectDetails

Deep Notes

History

  • Scheduled for RC Magnum channel, week of August 3, 2011.

Signature

function integer llSetMemoryLimit( integer limit );