P / Invoke - 如何使用c函数的结果将访问量加倍,该函数将地址返回到双精度数组

时间:2013-02-02 17:12:37

标签: c# c pinvoke

如何从函数fann_run()

获取float数组

这是它的C版。

fann_type *calc_out;
fann_type input[2];
struct fann *ann = fann_create_from_file("xor_float.net");
input[0] = -1;
input[1] = 1;
calc_out = fann_run(ann, input);
printf("xor test (%f,%f) -> %f\n", input[0], input[1], calc_out[0]);
fann_destroy(ann);

我在c#

中尝试这个
[DllImport("fannfloat.dll", EntryPoint = "fann_run")]
public static extern IntPtr fann_run(IntPtr _ann, float[] _input);

IntPtr ann = FANN.fann_create_from_file("Arial.net");
IntPtr result = FANN.fann_run(ann,input600);

现在我想使用'result'访问浮点数。 我怎样才能做到这一点 ?

1 个答案:

答案 0 :(得分:2)

如果您知道元素的数量,可以使用Marshal.Copy Method将非托管内存中的值复制到托管数组中:

float[] output = new float[7];
Marshal.Copy(result, output, 0, output.Length);

完成后不要忘记释放result

相关问题