기술 자료

Unity Engine

Unity Engine

Pass data between managed and unmanaged code

Exchange primitives, structures, arrays, and strings between managed C# code and unmanaged native code.
읽는 시간 1분최근 업데이트: 3일 전

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 introductionUnderstand 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 codeDeclare matching C# and C types so primitive values pass without data corruption.
Structures, classes, and unionsHow to pass complex types.
NativeArraysHow to pass NativeArray objects.
Pass strings between C# and native codeHow to pass string objects.

Additional resources