• Api Documentation
  • Source Code
Search Results for

    Show / Hide Table of Contents
    • SharpAssimp
      • Animation
      • AnimationBehaviour
      • AnimationInterpolation
      • AssimpContext
      • AssimpException
      • BlendMode
      • Bone
      • BoundingBox
      • Camera
      • CompileFlags
      • ConsoleLogStream
      • DefaultLogStream
      • EmbeddedTexture
      • ExcludeComponent
      • ExportDataBlob
      • ExportFormatDescription
      • Face
      • FileIOMode
      • FileIOSystem
      • FreeNativeDelegate
      • IMarshalable<Managed, Native>
      • INativeCustomMarshaler
      • IOStream
      • IOSystem
      • ImporterDescription
      • ImporterFeatureFlags
      • Light
      • LightSourceType
      • LogStream
      • LoggingCallback
      • Material
      • Material.PBRMaterialProperties
      • Material.ShaderMaterialProperties
      • MaterialProperty
      • Matrix3x3
      • MemoryHelper
      • Mesh
      • MeshAnimationAttachment
      • MeshAnimationChannel
      • MeshKey
      • MeshMorphAnimationChannel
      • MeshMorphKey
      • MeshMorphingMethod
      • MetaDataType
      • Metadata
      • Metadata.Entry
      • NativeCustomMarshalerAttribute
      • Node
      • NodeAnimationChannel
      • NodeCollection
      • Origin
      • PostProcessPreset
      • PostProcessSteps
      • PrimitiveType
      • PropertyType
      • QuaternionKey
      • Ray
      • ReturnCode
      • Scene
      • SceneFlags
      • ShadingMode
      • Texel
      • TextureFlags
      • TextureMapping
      • TextureOperation
      • TextureSlot
      • TextureType
      • TextureWrapMode
      • UVTransform
      • UVTransformFlags
      • VectorKey
      • VertexWeight
    • SharpAssimp.Configs
      • ACEvaluateSubdivisionConfig
      • ACSeparateBackfaceCullConfig
      • ASEReconstructNormalsConfig
      • AnimationAccuracyConfig
      • AppScaleConfig
      • BooleanPropertyConfig
      • ColladaIgnoreUpDirectionConfig
      • ColladaUseColladaNamesConfig
      • DeboneAllOrNoneConfig
      • DeboneThresholdConfig
      • ExportPointCloudsConfig
      • FBXConvertToMetersConfig
      • FBXImportAllGeometryLayersConfig
      • FBXImportAllMaterialsConfig
      • FBXImportAnimationsConfig
      • FBXImportCamerasConfig
      • FBXImportEmbeddedTexturesConfig
      • FBXImportEmbeddedTexturesLegacyNamingConfig
      • FBXImportLightsConfig
      • FBXImportMaterialsConfig
      • FBXOptimizeEmptyAnimationCurvesConfig
      • FBXPreservePivotsConfig
      • FBXStrictModeConfig
      • FavorSpeedConfig
      • FloatPropertyConfig
      • GlobalKeyFrameImportConfig
      • GlobalScaleConfig
      • IFCCylindricalTessellationConfig
      • IFCSkipSpaceRepresentationsConfig
      • IFCSmoothingAngleConfig
      • IFCUseCustomTriangulationConfig
      • IRRAnimationFrameRateConfig
      • IgnoreTextureCoordinatesConfig
      • IntegerPropertyConfig
      • KeepSceneHierarchyConfig
      • LWOImportOneLayerConfig
      • LWSAnimationEndConfig
      • LWSAnimationStartConfig
      • MD2KeyFrameImportConfig
      • MD3HandleMultiPartConfig
      • MD3KeyFrameImportConfig
      • MD3ShaderSourceConfig
      • MD3SkinNameConfig
      • MD5NoAnimationAutoLoadConfig
      • MDLColorMapConfig
      • MDLKeyFrameImportConfig
      • MaterialExcludeListConfig
      • MatrixPropertyConfig
      • MaxBoneCountConfig
      • MeasureTimeConfig
      • MeshTriangleLimitConfig
      • MeshVertexLimitConfig
      • MultithreadingConfig
      • NoSkeletonMeshesConfig
      • NodeExcludeListConfig
      • NormalSmoothingAngleConfig
      • NormalizeVertexComponentsConfig
      • OgreMaterialFileConfig
      • OgreTextureTypeFromFilenameConfig
      • PropertyConfig
      • RemoveComponentConfig
      • RemoveDegeneratePrimitivesCheckAreaConfig
      • RemoveDegeneratePrimitivesConfig
      • RemoveEmptyBonesConfig
      • RootTransformationConfig
      • SMDKeyFrameImportConfig
      • SmdLoadAnimationListConfig
      • SortByPrimitiveTypeConfig
      • StringPropertyConfig
      • TangentSmoothingAngleConfig
      • TangentTextureChannelIndexConfig
      • TerragenComputeTexCoordsConfig
      • TransformUVConfig
      • UnrealHandleFlagsConfig
      • UnrealKeyFrameImportConfig
      • VertexBoneWeightLimitConfig
      • VertexCacheSizeConfig
      • XFileUseDoublesConfig
    • SharpAssimp.Unmanaged
      • AiAnimMesh
      • AiAnimation
      • AiBone
      • AiCamera
      • AiConfigs
      • AiDefines
      • AiExportDataBlob
      • AiExportFormatDesc
      • AiFace
      • AiFile
      • AiFileCloseProc
      • AiFileFlushProc
      • AiFileIO
      • AiFileOpenProc
      • AiFileReadProc
      • AiFileSeek
      • AiFileTellProc
      • AiFileWriteProc
      • AiImporterDesc
      • AiLight
      • AiLogStream
      • AiLogStreamCallback
      • AiMatKeys
      • AiMaterial
      • AiMaterialProperty
      • AiMemoryInfo
      • AiMesh
      • AiMeshAnim
      • AiMeshColorArray
      • AiMeshMorphAnim
      • AiMeshMorphKey
      • AiMeshTextureCoordinateArray
      • AiMeshUVComponentArray
      • AiMetadata
      • AiMetadataEntry
      • AiNode
      • AiNodeAnim
      • AiScene
      • AiString
      • AiTexture
      • AssimpLibrary
      • Platform
      • UnmanagedFunctionNameAttribute
      • UnmanagedLibrary
      • UnmanagedLibraryResolver

    Class MemoryHelper

    Helper static class containing functions that aid dealing with unmanaged memory to managed memory conversions.

    Inheritance
    object
    MemoryHelper
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: SharpAssimp
    Assembly: SharpAssimp.dll
    Syntax
    public static class MemoryHelper

    Methods

    | Edit this page View Source

    AllocateMemory(int, int)

    Allocates unmanaged memory. This memory should only be freed by this helper.

    Declaration
    public static nint AllocateMemory(int sizeInBytes, int alignment = 16)
    Parameters
    Type Name Description
    int sizeInBytes

    Size to allocate

    int alignment

    Alignment of the memory, by default aligned along 16-byte boundary.

    Returns
    Type Description
    nint

    Pointer to the allocated unmanaged memory.

    | Edit this page View Source

    AsRef<T>(nint)

    Casts the pointer into a by-ref value of the specified type.

    Declaration
    public static ref T AsRef<T>(nint pSrc) where T : struct
    Parameters
    Type Name Description
    nint pSrc

    Memory location.

    Returns
    Type Description
    T

    By-ref value.

    Type Parameters
    Name Description
    T

    Struct type.

    | Edit this page View Source

    ClearMemory(nint, int)

    Clears the memory to zero.

    Declaration
    public static void ClearMemory(nint memoryPtr, int sizeInBytesToClear)
    Parameters
    Type Name Description
    nint memoryPtr

    Pointer to the memory.

    int sizeInBytesToClear

    Number of bytes, starting from the memory pointer, to clear.

    | Edit this page View Source

    CopyMemory(nint, nint, int)

    Performs a memcopy that copies data from the memory pointed to by the source pointer to the memory pointer by the destination pointer.

    Declaration
    public static void CopyMemory(nint pDest, nint pSrc, int sizeInBytesToCopy)
    Parameters
    Type Name Description
    nint pDest

    Destination memory location

    nint pSrc

    Source memory location

    int sizeInBytesToCopy

    Number of bytes to copy

    | Edit this page View Source

    FreeMemory(nint)

    Frees unmanaged memory that was allocated by this helper.

    Declaration
    public static void FreeMemory(nint memoryPtr)
    Parameters
    Type Name Description
    nint memoryPtr

    Pointer to unmanaged memory to free.

    | Edit this page View Source

    FreeNativeArray<T>(nint, int, FreeNativeDelegate, bool)

    Frees an unmanaged array and performs cleanup for each value. Optionally can free an array of pointers. This can be used on any type that can be marshaled into unmanaged memory.

    Declaration
    public static void FreeNativeArray<T>(nint nativeArray, int length, FreeNativeDelegate action, bool arrayOfPointers = false) where T : struct
    Parameters
    Type Name Description
    nint nativeArray

    Pointer to unmanaged memory

    int length

    Number of elements to free

    FreeNativeDelegate action

    Delegate that performs the necessary cleanup

    bool arrayOfPointers

    True if the pointer is an array of pointers, false otherwise.

    Type Parameters
    Name Description
    T

    Struct type

    | Edit this page View Source

    FromNativeArray<T>(nint, int)

    Marshals an array of blittable structs from a c-style unmanaged array (void*). This should not be used on non-blittable types that require marshaling by the runtime (e.g. has MarshalAs attributes).

    Declaration
    public static T[] FromNativeArray<T>(nint nativeArray, int length) where T : struct
    Parameters
    Type Name Description
    nint nativeArray

    Pointer to unmanaged memory

    int length

    Number of elements to read

    Returns
    Type Description
    T[]

    Managed array

    Type Parameters
    Name Description
    T

    Struct type

    | Edit this page View Source

    FromNativeArray<Managed, Native>(nint, int, bool)

    Marshals an array of managed values from a c-style unmanaged array (void*). This also can optionally marshal from an unmanaged array of pointers (void**).

    Declaration
    public static Managed[] FromNativeArray<Managed, Native>(nint nativeArray, int length, bool arrayOfPointers = false) where Managed : class, IMarshalable<Managed, Native>, new() where Native : struct
    Parameters
    Type Name Description
    nint nativeArray

    Pointer to unmanaged memory

    int length

    Number of elements to marshal

    bool arrayOfPointers

    True if the pointer is an array of pointers, false otherwise.

    Returns
    Type Description
    Managed[]

    Marshaled managed values

    Type Parameters
    Name Description
    Managed

    Managed type

    Native

    Native type

    | Edit this page View Source

    FromNativePointer<Managed, Native>(nint)

    Marshals a managed value from unmanaged memory.

    Declaration
    public static Managed? FromNativePointer<Managed, Native>(nint ptr) where Managed : class, IMarshalable<Managed, Native>, new() where Native : struct
    Parameters
    Type Name Description
    nint ptr

    Pointer to unmanaged memory

    Returns
    Type Description
    Managed

    The marshaled managed value

    Type Parameters
    Name Description
    Managed

    Managed type

    Native

    Unmanaged type

    | Edit this page View Source

    MarshalPointer<T>(in T, nint)

    Convienence method for marshaling a structure to a pointer. Only use if the type is not blittable, otherwise use the write methods for blittable types.

    Declaration
    public static void MarshalPointer<T>(in T value, nint ptr) where T : struct
    Parameters
    Type Name Description
    T value

    Struct to marshal

    nint ptr

    Pointer to unmanaged chunk of memory which must be allocated prior to this call

    Type Parameters
    Name Description
    T

    Struct type

    | Edit this page View Source

    MarshalSizeOf<T>()

    Computes the size of the struct type using Marshal SizeOf. Only use if the type is not blittable, thus requiring marshaling by the runtime, (e.g. has MarshalAs attributes), otherwise use the SizeOf methods for blittable types.

    Declaration
    public static int MarshalSizeOf<T>() where T : struct
    Returns
    Type Description
    int

    Size of the struct in bytes.

    Type Parameters
    Name Description
    T

    Struct type

    | Edit this page View Source

    MarshalStructure<T>(nint)

    Convienence method for marshaling a pointer to a structure. Only use if the type is not blittable, otherwise use the read methods for blittable types.

    Declaration
    public static T MarshalStructure<T>(nint ptr) where T : struct
    Parameters
    Type Name Description
    nint ptr

    Pointer to marshal

    Returns
    Type Description
    T

    The marshaled structure

    Type Parameters
    Name Description
    T

    Struct type

    | Edit this page View Source

    MarshalStructure<T>(nint, out T)

    Convienence method for marshaling a pointer to a structure. Only use if the type is not blittable, otherwise use the read methods for blittable types.

    Declaration
    public static void MarshalStructure<T>(nint ptr, out T value) where T : struct
    Parameters
    Type Name Description
    nint ptr

    Pointer to marshal

    T value

    The marshaled structure

    Type Parameters
    Name Description
    T

    Struct type

    | Edit this page View Source

    ReadStreamFully(Stream, int)

    Reads a stream until the end is reached into a byte array. Based on Jon Skeet's implementation. It is up to the caller to dispose of the stream.

    Declaration
    public static byte[] ReadStreamFully(Stream stream, int initialLength)
    Parameters
    Type Name Description
    Stream stream

    Stream to read all bytes from

    int initialLength

    Initial buffer length, default is 32K

    Returns
    Type Description
    byte[]

    The byte array containing all the bytes from the stream

    | Edit this page View Source

    Read<T>(nint)

    Reads a single element from the memory location.

    Declaration
    public static T Read<T>(nint pSrc) where T : struct
    Parameters
    Type Name Description
    nint pSrc

    Pointer to memory location

    Returns
    Type Description
    T

    The read value

    Type Parameters
    Name Description
    T

    Struct type

    | Edit this page View Source

    Read<T>(nint, out T)

    Reads a single element from the memory location.

    Declaration
    public static void Read<T>(nint pSrc, out T value) where T : struct
    Parameters
    Type Name Description
    nint pSrc

    Pointer to memory location

    T value

    The read value.

    Type Parameters
    Name Description
    T

    Struct type

    | Edit this page View Source

    Read<T>(nint, T[], int, int)

    Reads data from the memory location into the array.

    Declaration
    public static void Read<T>(nint pSrc, T[] data, int startIndexInArray, int count) where T : struct
    Parameters
    Type Name Description
    nint pSrc

    Pointer to memory location

    T[] data

    Array to store the copied data

    int startIndexInArray

    Zero-based element index to start writing data to in the element array.

    int count

    Number of elements to copy

    Type Parameters
    Name Description
    T

    Struct type

    | Edit this page View Source

    SizeOf<T>()

    Computes the size of the struct type.

    Declaration
    public static int SizeOf<T>() where T : struct
    Returns
    Type Description
    int

    Size of the struct in bytes.

    Type Parameters
    Name Description
    T

    Struct type

    | Edit this page View Source

    SizeOf<T>(T[])

    Computes the size of the struct array.

    Declaration
    public static int SizeOf<T>(T[] array) where T : struct
    Parameters
    Type Name Description
    T[] array

    Array of structs

    Returns
    Type Description
    int

    Total size, in bytes, of the array's contents.

    Type Parameters
    Name Description
    T

    Struct type

    | Edit this page View Source

    ToNativeArray<T>(List<T>)

    Marshals a list of blittable structs to a c-style unmanaged array (void*). This should not be used on non-blittable types that require marshaling by the runtime (e.g. has MarshalAs attributes).

    Declaration
    public static nint ToNativeArray<T>(List<T> managedArray) where T : struct
    Parameters
    Type Name Description
    List<T> managedArray

    Managed list of structs

    Returns
    Type Description
    nint

    Pointer to unmanaged memory

    Type Parameters
    Name Description
    T

    Struct type

    | Edit this page View Source

    ToNativeArray<T>(T[]?)

    Marshals an array of blittable structs to a c-style unmanaged array (void*). This should not be used on non-blittable types that require marshaling by the runtime (e.g. has MarshalAs attributes).

    Declaration
    public static nint ToNativeArray<T>(T[]? managedArray) where T : struct
    Parameters
    Type Name Description
    T[] managedArray

    Managed array of structs

    Returns
    Type Description
    nint

    Pointer to unmanaged memory

    Type Parameters
    Name Description
    T

    Struct type

    | Edit this page View Source

    ToNativeArray<Managed, Native>(IReadOnlyCollection<Managed>?, bool)

    Marshals an array of managed values to a c-style unmanaged array (void*). This also can optionally marshal to an unmanaged array of pointers (void**).

    Declaration
    public static nint ToNativeArray<Managed, Native>(IReadOnlyCollection<Managed>? managedColl, bool arrayOfPointers = false) where Managed : class, IMarshalable<Managed, Native>, new() where Native : struct
    Parameters
    Type Name Description
    IReadOnlyCollection<Managed> managedColl

    Collection of managed values

    bool arrayOfPointers

    True if the pointer is an array of pointers, false otherwise.

    Returns
    Type Description
    nint

    Pointer to unmanaged memory

    Type Parameters
    Name Description
    Managed

    Managed type

    Native

    Native type

    | Edit this page View Source

    ToNativePointer<Managed, Native>(Managed)

    Marshals a managed value to unmanaged memory.

    Declaration
    public static nint ToNativePointer<Managed, Native>(Managed managedValue) where Managed : class, IMarshalable<Managed, Native>, new() where Native : struct
    Parameters
    Type Name Description
    Managed managedValue

    Managed value to marshal

    Returns
    Type Description
    nint

    Pointer to unmanaged memory

    Type Parameters
    Name Description
    Managed

    Managed type

    Native

    Unmanaged type

    | Edit this page View Source

    Write<T>(nint, List<T>, int, int)

    Writes data from the list to the memory location.

    Declaration
    public static void Write<T>(nint pDest, List<T> data, int startIndexInArray, int count) where T : struct
    Parameters
    Type Name Description
    nint pDest

    Pointer to memory location

    List<T> data

    List containing data to write

    int startIndexInArray

    Zero-based element index to start reading data from in the element array.

    int count

    Number of elements to copy

    Type Parameters
    Name Description
    T

    Struct type

    | Edit this page View Source

    Write<T>(nint, in T)

    Writes a single element to the memory location.

    Declaration
    public static void Write<T>(nint pDest, in T data) where T : struct
    Parameters
    Type Name Description
    nint pDest

    Pointer to memory location

    T data

    The value to write

    Type Parameters
    Name Description
    T

    Struct type

    | Edit this page View Source

    Write<T>(nint, T[], int, int)

    Writes data from the array to the memory location.

    Declaration
    public static void Write<T>(nint pDest, T[] data, int startIndexInArray, int count) where T : struct
    Parameters
    Type Name Description
    nint pDest

    Pointer to memory location

    T[] data

    Array containing data to write

    int startIndexInArray

    Zero-based element index to start reading data from in the element array.

    int count

    Number of elements to copy

    Type Parameters
    Name Description
    T

    Struct type

    • Edit this page
    • View Source
    In this article
    Back to top Copyright (c) 2012-2020 Nicholas Woodfield, (c) 2024 Salvage, (c) 2025 Jérémy Ansel