diff --git a/src/Aardvark.Base.FSharp/Utilities/Interop/FSLibExtensions.fs b/src/Aardvark.Base.FSharp/Utilities/Interop/FSLibExtensions.fs index 206b1425..cd4fc62c 100644 --- a/src/Aardvark.Base.FSharp/Utilities/Interop/FSLibExtensions.fs +++ b/src/Aardvark.Base.FSharp/Utilities/Interop/FSLibExtensions.fs @@ -214,6 +214,8 @@ module Prelude = let inline sndv (struct (_, y)) = y type nativeptr<'T when 'T : unmanaged> with + member inline ptr.Address = NativePtr.toNativeInt ptr + member ptr.Value with inline get () = NativePtr.read ptr and inline set (value : 'T) = NativePtr.write ptr value diff --git a/src/Aardvark.Base.FSharp/Utilities/Native.fs b/src/Aardvark.Base.FSharp/Utilities/Native.fs index 30a225e2..2e09818b 100644 --- a/src/Aardvark.Base.FSharp/Utilities/Native.fs +++ b/src/Aardvark.Base.FSharp/Utilities/Native.fs @@ -182,6 +182,14 @@ module NativeUtilities = finally gc.Free() + let inline pin ([] f: nativeptr<'T> -> 'U) (value: 'T) = + use ptr = fixed &value + f ptr + + let inline pinArr ([] f: nativeptr<'T> -> 'U) (array: 'T[]) = + use ptr = fixed array + f ptr + [] module MarshalDelegateExtensions = open System.Collections.Concurrent