Memory

Memory Class

The Memory class reports on script pool memory use.

Syntax

public class Memory : InstanceInterface

Remarks

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

C# Example
/* 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: "� 2017 Linden Research, 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. � 2017 Linden Research, 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()));
    }
}
  • 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.

Requirements

Namespace: Sansar.Script
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Members

See Also: Inherited members from InstanceInterface.

Public Properties

[read-only]
 
ActivityLevel float . Current memory activity level since start of last memory counting.
[read-only]
 
IsValid bool . Whether or not this interface is valid. (Inherited from InstanceInterface.)
[read-only]
 
PeakUsedBytes uint . The highest level of memory used by the script pool.
[read-only]
 
PolicyCritical uint . Current policy Critical level of used memory by the script pool
[read-only]
 
PolicyLimit uint . Current policy Limit level of used memory by the script pool
[read-only]
 
PolicyWarning uint . Current policy Warning level of used memory by the script pool
[read-only]
 
UsedBytes uint . Total bytes used by this script pool as of last accounting.

Public Methods

 
Subscribe (Memory.SubscriptionHandler, bool)
Subscribes to Memory Events.
 
Subscribe (Action<MemoryData>, bool) : IEventSubscription
Subscribes to Memory Events.
override
ToString () : string
A string representation of this object.

Member Details

ActivityLevel Property

Current memory activity level since start of last memory counting.

Syntax

public float ActivityLevel { get; }

Value

uint

Remarks

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

Requirements

Namespace: Sansar.Script
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

PeakUsedBytes Property

The highest level of memory used by the script pool.

Syntax

public uint PeakUsedBytes { get; }

Value

uint

Remarks

The peak is reset when the server resets.

Requirements

Namespace: Sansar.Script
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

PolicyCritical Property

Current policy Critical level of used memory by the script pool

Syntax

public uint PolicyCritical { get; }

Value

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.

Requirements

Namespace: Sansar.Script
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

PolicyLimit Property

Current policy Limit level of used memory by the script pool

Syntax

public uint PolicyLimit { get; }

Value

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.

Requirements

Namespace: Sansar.Script
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

PolicyWarning Property

Current policy Warning level of used memory by the script pool

Syntax

public uint PolicyWarning { get; }

Value

uint

Remarks

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

Requirements

Namespace: Sansar.Script
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Subscribe Method

Subscribes to Memory Events.

Syntax

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

Parameters

callback
Callback which is executed when the event completes.
persistent
Optional, set to false to unsubscribe after one event.

Remarks

 

Requirements

Namespace: Sansar.Script
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Subscribe Method

Subscribes to Memory Events.

Syntax

public IEventSubscription Subscribe (Action<MemoryData> callback, bool persistent)

See Also

Parameters

callback
Callback which is executed when the event completes.
persistent
Optional, set to false to unsubscribe after one event.

Returns

An Sansar.Script.IEventSubscription that can be used to cancel the subscription.

Remarks

 

Requirements

Namespace: Sansar.Script
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

ToString Method

A string representation of this object.

Syntax

public override string ToString ()

Returns

A string representation of this object.

Remarks

The format of this string may change between releases.

Requirements

Namespace: Sansar.Script
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

UsedBytes Property

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

Syntax

public uint UsedBytes { get; }

Value

uint

Remarks

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

Requirements

Namespace: Sansar.Script
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0


Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Article is closed for comments.