MemoryManager is a singleton class that manages the memory allocation and buffers for the Rhodonite library. It handles different types of buffers including CPU generic data, GPU instance data, and GPU vertex data.

Accessors

  • get bufferHeightLength(): number
  • Gets the buffer height length from the configuration.

    Returns number

    The data texture height from Config

  • get bufferWidthLength(): number
  • Gets the buffer width length from the configuration.

    Returns number

    The data texture width from Config

Methods

  • Creates a buffer on-demand with custom size and alignment for a specific object. These buffers are typically used for UBOs (Uniform Buffer Objects).

    Parameters

    • size: number

      The size of the buffer in bytes

    • object: RnObject

      The RnObject that will own this buffer

    • byteAlign: number

      The byte alignment requirement for the buffer

    Returns Buffer

    The newly created Buffer instance

  • Gets an existing buffer or creates a new one if it doesn't exist.

    Parameters

    • bufferUse: EnumIO

      The type of buffer to retrieve or create

    Returns Buffer

    The Buffer instance (existing or newly created)

  • Dumps the contents of a buffer to a downloadable file for debugging purposes.

    Parameters

    • bufferUse: EnumIO

      The type of buffer to dump

    Returns undefined | Buffer

    The Buffer instance that was dumped, or undefined if the buffer doesn't exist

  • Retrieves an existing buffer for the specified buffer use type.

    Parameters

    • bufferUse: EnumIO

      The type of buffer to retrieve

    Returns undefined | Buffer

    The Buffer instance if it exists, undefined otherwise

  • Retrieves an on-demand buffer associated with a specific object.

    Parameters

    • object: RnObject

      The RnObject whose buffer to retrieve

    Returns undefined | Buffer

    The Buffer instance if it exists, undefined otherwise

  • Calculates the total memory size based on buffer dimensions and data format.

    Returns number

    The total memory size in bytes (width × height × 4 channels × 4 bytes per channel)

  • Prints memory usage statistics for all managed buffers to the console. Shows used bytes, total bytes, and usage percentage for each buffer type.

    Returns void

  • Creates a MemoryManager instance if it doesn't exist, or returns the existing instance. This method enforces the singleton pattern.

    Parameters

    • config: {
          cpuGeneric: number;
          gpuInstanceData: number;
          gpuVertexData: number;
      }

      Configuration object containing memory size ratios

      • cpuGeneric: number

        Memory size ratio for CPU generic data

      • gpuInstanceData: number

        Memory size ratio for GPU instance data

      • gpuVertexData: number

        Memory size ratio for GPU vertex data

    Returns MemoryManager

    The MemoryManager singleton instance