Converting a pointer C# type to F#?

最后都变了- 提交于 2019-12-13 02:14:05

问题


I am just a beginner in programing i wish covert some code from C# to F#,

I have encotered this code:

float[] v1=new float[10]

I need to use this pointer to pass to the function:

ComputeBuffer<float> bufV1 = 
  new ComputeBuffer<float>(Context, ComputeMemoryFlags.ReadWrite |
         ComputeMemoryFlags.UseHostPointer, v1);

If i creat an array in F# like this:

let v1 = [| 1.0..10.0 |]

and call now the funaction like this:

let bufV1 = new ComputeBuffer<float>(Context, 
    ComputeMemoryFlags.ReadWrite ||| 
        ComputeMemoryFlags.UseHostPointer, v1)

Is it an error?? How do i pass a pointer??


回答1:


(In .NET, we call these things references to objects; v1 is a reference to an array object. Pointers are something different.)

Note that what F# refers to as float is what C# calls a double. You might need

let v1 = [| 1.0f .. 10.0f |]

where the f suffix makes the values be F# float32s (e.g. C# floats).




回答2:


not an error.

Need to point out that v1 is not a pointer, it is an object in .Net.



来源:https://stackoverflow.com/questions/2981126/converting-a-pointer-c-sharp-type-to-f

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!