Skip to content

Get Sansar

Script API

Memory

Where: Client
More page actions

For the complete documentation index, see llms.txt. This page is also available as Markdown.

Class Namespace Sansar.Script Inherits InstanceInterface

The Memory class reports on script pool memory use.

public class Memory : InstanceInterface

Remarks

Memory use is tracked by groups of scripts called “pools”. There are two types of pools:

  • Scene: The scripts attached to the scene and to objects built into the scene all share a pool that is allowed a large amount of memory.
  • Guests: Scripts associated with each visiting user share their own pool independent of other users. These pools are allowed a smaller amount of memory.

The Policy properties will reflect the use levels for the type of pool this script is associated with.

Example

MemoryExample.cs
/* This content is licensed under the terms of the Creative Commons Attribution 4.0 International License.
* When using this content, you must:
* • Acknowledge that the content is from the Sansar Knowledge Base.
* • Include our copyright notice: "2022 Sansar, Inc."
* • Indicate that the content is licensed under the Creative Commons Attribution-Share Alike 4.0 International License.
* • Include the URL for, or link to, the license summary at https://creativecommons.org/licenses/by-sa/4.0/deed.hi (and, if possible, to the complete license terms at https://creativecommons.org/licenses/by-sa/4.0/legalcode.
* For example:
* "This work uses content from the Sansar Knowledge Base. © 2022 Sansar, Inc." Licensed under the Creative Commons Attribution 4.0 International License (license summary available at https://creativecommons.org/licenses/by/4.0/ and complete license terms available at https://creativecommons.org/licenses/by/4.0/legalcode)."
*/
using System;
using Sansar.Script;
using Sansar.Simulation;
// This example shows how to track and report on script memory use.
// Memory use is tracked by "pool". There are two types of pools:
// Scene: The scripts attached to the scene all share a pool that is allowed a large amount of memory
// User: Scripts associated with each user share their own pool and are allowed a smaller amount of memory
public class MemoryExample : SceneObjectScript
{
// Set the Report_Command in the object properties to the chat command used to get the memory report.
[DefaultValue("/memory")]
[DisplayName("Report Command")]
public readonly string Report_Command = "/memory";
private MemoryUseLevel memoryLevel = MemoryUseLevel.Low;
public override void Init()
{
//When the memory level changes, store the new memory level.
// If used in a more complex script this event could be used to clear log history or otherwise reduce used memory
Memory.Subscribe((data) => { memoryLevel = data.UseLevel; });
// Set a chat subscription that will call ReportMemory when anyone says the Report_Command
ScenePrivate.Chat.Subscribe(0, null, (data) => { if (data.Message == Report_Command) ReportMemory(ScenePrivate.FindAgent(data.SourceId)); });
}
// Reports the last recorded memory level from an event along with current Memory data.
private void ReportMemory(AgentPrivate agent)
{
agent.SendChat(String.Format("Memory info: [{0}] {1}", memoryLevel.ToString(), Memory.ToString()));
}
}

Source: Examples/MemoryExample.cs in the Sansar 47.10.0 client ScriptApi snapshot.

Members at a glance

KindMembers
PropertiesActivityLevel · PeakUsedBytes · PolicyCritical · PolicyLimit · PolicyWarning · UsedBytes
MethodsSubscribe · ToString

Properties

ActivityLevel

public float ActivityLevel { get; }

Current memory activity level since start of last memory counting.

Value: float — uint

Remarks

Returns a measure of the pools memory activity since the start of the last counting run.

Activity levels are 0-1: Low activity, 1-2: Medium activity, >2: High activity.

Activity level is used to determine when memory counting is required with more active memory use requiring more frequent memory counting.

PeakUsedBytes

public uint PeakUsedBytes { get; }

The highest level of memory used by the script pool.

Value: uint — uint

Remarks

The peak is reset when the server resets.

PolicyCritical

public uint PolicyCritical { get; }

Current policy Critical level of used memory by the script pool

Value: uint — uint

Remarks

When the memory used in the pool passes this mark events will be sent to scripts subscribed to ScriptMemoryEvents and memory counting will become more frequent.

PolicyLimit

public uint PolicyLimit { get; }

Current policy Limit level of used memory by the script pool

Value: uint — uint

Remarks

When the memory used in the pool passes this mark events will be sent to scripts subscribed to ScriptMemoryEvents. Script pools that stay above this limit may be stopped or removed from the scene.

PolicyWarning

public uint PolicyWarning { get; }

Current policy Warning level of used memory by the script pool

Value: uint — uint

Remarks

When the memory used in the pool passes this mark events will be sent to scripts subscribed to ScriptMemoryEvents

UsedBytes

public uint UsedBytes { get; }

Total bytes used by this script pool as of last accounting.

Value: uint — uint

Remarks

Memory is counted based on script activity in the scene across all pools. Memory.ActivityLevel

Methods

Subscribe

Deprecated
[System.Obsolete("Use subscription callbacks of type Action<Sansar.Script.MemoryData>", false)] public void Subscribe(     Memory.SubscriptionHandler callback,     bool persistent )

Subscribes to Memory Events.

ParameterTypeDescription
callbackMemory.SubscriptionHandlerCallback which is executed when the event completes.
persistentboolOptional, set to false to unsubscribe after one event.
public IEventSubscription Subscribe(     Action<MemoryData> callback,     bool persistent )

Subscribes to Memory Events.

ParameterTypeDescription
callbackAction<MemoryData>Callback which is executed when the event completes.
persistentboolOptional, set to false to unsubscribe after one event.

Returns: IEventSubscription — An IEventSubscription that can be used to cancel the subscription.

ToString

public override string ToString()

A string representation of this object.

Returns: string — A string representation of this object.

Remarks

The format of this string may change between releases.

Used in examples

Generated from the Sansar 47.10.0 client ScriptApi snapshot.