docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct RewindableAllocator

    An allocator that is fast like a linear allocator, is threadsafe, and automatically invalidates all allocations made from it, when "rewound" by the user.

    Implements
    AllocatorManager.IAllocator
    Namespace: Unity.Collections
    Assembly: Unity.Collections.dll
    Syntax
    public struct RewindableAllocator : AllocatorManager.IAllocator

    Properties

    BlocksAllocated

    Retrieves the number of memory blocks that the allocator has requested from the system.

    Declaration
    public int BlocksAllocated { get; }
    Property Value
    Type Description
    int

    Function

    All allocators must implement this property, in order to be installed in the custom allocator table.

    Declaration
    public AllocatorManager.TryFunction Function { get; }
    Property Value
    Type Description
    AllocatorManager.TryFunction

    Handle

    Retrieve the AllocatorHandle associated with this allocator. The handle is used as an index into a global table, for times when a reference to the allocator object isn't available.

    Declaration
    public AllocatorManager.AllocatorHandle Handle { get; set; }
    Property Value
    Type Description
    AllocatorManager.AllocatorHandle

    InitialSizeInBytes

    Retrieves the size of the initial memory block, as requested in the Initialize function.

    Declaration
    public int InitialSizeInBytes { get; }
    Property Value
    Type Description
    int

    IsCustomAllocator

    Check whether an allocator is a custom allocator

    Declaration
    public bool IsCustomAllocator { get; }
    Property Value
    Type Description
    bool

    ToAllocator

    Retrieve the Allocator associated with this allocator.

    Declaration
    public Allocator ToAllocator { get; }
    Property Value
    Type Description
    Allocator

    Methods

    AllocateNativeArray<T>(int)

    Allocate a NativeArray of type T from memory that is guaranteed to remain valid until the end of the next Update of this World. There is no need to Dispose the NativeArray so allocated. It is not possible to free the memory by Disposing it - it is automatically freed after the end of the next Update for this World.

    Declaration
    public NativeArray<T> AllocateNativeArray<T>(int length) where T : struct
    Parameters
    Type Name Description
    int length

    The length of the NativeArray to allocate, measured in elements.

    Returns
    Type Description
    NativeArray<T>

    The NativeArray allocated by this function.

    Type Parameters
    Name Description
    T

    The element type of the NativeArray to allocate.

    AllocateNativeList<T>(int)

    Allocate a NativeList of type T from memory that is guaranteed to remain valid until the end of the next Update of this World. There is no need to Dispose the NativeList so allocated. It is not possible to free the memory by Disposing it - it is automatically freed after the end of the next Update for this World. The NativeList must be initialized with its maximum capacity; if it were to dynamically resize, up to 1/2 of the total final capacity would be wasted, because the memory can't be dynamically freed.

    Declaration
    public NativeList<T> AllocateNativeList<T>(int capacity) where T : unmanaged
    Parameters
    Type Name Description
    int capacity

    The capacity of the NativeList to allocate, measured in elements.

    Returns
    Type Description
    NativeList<T>

    The NativeList allocated by this function.

    Type Parameters
    Name Description
    T

    The element type of the NativeList to allocate.

    Dispose()

    Dispose the allocator. This must be called to free the memory blocks that were allocated from the system.

    Declaration
    public void Dispose()

    Initialize(int)

    Initializes the allocator. Must be called before first use.

    Declaration
    public void Initialize(int initialSizeInBytes)
    Parameters
    Type Name Description
    int initialSizeInBytes

    The initial capacity of the allocator, in bytes

    Rewind()

    Rewind the allocator; invalidate all allocations made from it, and potentially also free memory blocks it has allocated from the system.

    Declaration
    public void Rewind()

    Try(ref Block)

    Try to allocate, free, or reallocate a block of memory. This is an internal function, and is not generally called by the user.

    Declaration
    public int Try(ref AllocatorManager.Block block)
    Parameters
    Type Name Description
    AllocatorManager.Block block

    The memory block to allocate, free, or reallocate

    Returns
    Type Description
    int

    Implements

    AllocatorManager.IAllocator

    Extension Methods

    AllocatorManager.Register<T>(ref T)
    AllocatorManager.Unregister<T>(ref T)
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)