Version: Unity 6.0 (6000.0)
Language : English
Import unmanaged functions as C# methods
Pass data between managed and unmanaged code introduction

Pass data between managed and unmanaged code

When you call functions across the boundary between managed C# code and unmanaged native code, both sides must agree on the memory layout of the data and how long it stays in memory. How you pass data depends on its type: primitive values, structs and unions, NativeArrays, and strings each need different handling.

Topic Description
Pass data between managed and unmanaged code introduction Understand how the stack, the managed heap, and marshalling affect data you pass to native code, and when to pin data in memory.
Match primitive types between C# and native code Declare matching C# and C types so primitive values pass without data corruption.
Structures, classes, and unions How to pass complex types.
NativeArrays How to pass NativeArray objects.
Pass strings between C# and native code How to pass string objects.

Additional resources

Import unmanaged functions as C# methods
Pass data between managed and unmanaged code introduction