简体   繁体   English

如何编组包含未知大小的 int 数组的结构?

[英]How do I marshal a structure containing a array of int of unknown size?

I have a c-structure that I want to return from a c-function to c# and that structure contains an array of int and a length.我有一个 c 结构,我想从 c 函数返回到 c#,该结构包含一个 int 数组和一个长度。 So basically所以基本上

struct MyStruct
{
int *arr;
int size;
} 

How should I allocate the arr in c to ensure that it can be freed in c#.我应该如何在 c 中分配 arr 以确保它可以在 c# 中被释放。 And how do I decorate the corresponding structure in c# to make the marshalling possible?以及如何在 c# 中装饰相应的结构以使编组成为可能?

You can't.你不能。 You should allocate and free memory by same runtime library.您应该通过相同的运行时库分配和释放内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM