{!See https://docs.google.com/document/d/1takg_GmIBBKKTj-GHZCwzxohpQz7Bhekivkk72kYMtE/edit for reference implementation of OneTrust, dataLayer and GTM} {!OneTrust Cookies Consent} {!OneTrust Cookies Consent end} {!dataLayer initialization push} {!dataLayer initialization push end} {!Google Tag Manager} {!Google Tag Manager end} Struct NativeStream | Collections | 2.3.0-pre.3
docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct NativeStream

    A set of untyped, append-only buffers. Allows for concurrent reading and concurrent writing without synchronization.

    Implements
    INativeDisposable
    Namespace: Unity.Collections
    Assembly: solution.dll
    Syntax
    [NativeContainer]
    public struct NativeStream : INativeDisposable
    Remarks

    As long as each individual buffer is written in one thread and read in one thread, multiple threads can read and write the stream concurrently, e.g. while thread A reads from buffer X of a stream, thread B can read from buffer Y of the same stream.

    Each buffer is stored as a chain of blocks. When a write exceeds a buffer's current capacity, another block is allocated and added to the end of the chain. Effectively, expanding the buffer never requires copying the existing data (unlike with NativeList<T>, for example).

    All writing to a stream should be completed before the stream is first read. Do not write to a stream after the first read. Violating these rules won't necessarily cause any problems, but they are the intended usage pattern.

    Writing is done with NativeStream.Writer, and reading is done with NativeStream.Reader. An individual reader or writer cannot be used concurrently across threads: each thread must use its own.

    The data written to an individual buffer can be heterogeneous in type, and the data written to different buffers of a stream can be entirely different in type, number, and order. Just make sure that the code reading from a particular buffer knows what to expect to read from it.

    Constructors

    Name Description
    NativeStream(int, AllocatorHandle)

    Initializes and returns an instance of NativeStream.

    Properties

    Name Description
    ForEachCount

    The number of buffers in this stream.

    IsCreated

    Whether this stream has been allocated (and not yet deallocated).

    Methods

    Name Description
    AsReader()

    Returns a reader of this stream.

    AsWriter()

    Returns a writer of this stream.

    Count()

    Returns the total number of items in the buffers of this stream.

    Dispose()

    Releases all resources (memory and safety handles).

    Dispose(JobHandle)

    Creates and schedules a job that will release all resources (memory and safety handles) of this stream.

    IsEmpty()

    Returns true if this stream is empty.

    ScheduleConstruct(out NativeStream, NativeArray<int>, JobHandle, AllocatorHandle)

    Creates and schedules a job to allocate a new stream.

    ScheduleConstruct<T>(out NativeStream, NativeList<T>, JobHandle, AllocatorHandle)

    Creates and schedules a job to allocate a new stream.

    ToNativeArray<T>(AllocatorHandle)

    Returns a new NativeArray copy of this stream's data.

    In This Article
    Back to top
    Copyright © 2023 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)