Brendon
Brendon

Reputation: 11

Converting a pointer C# type to F#?

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??

Upvotes: 1

Views: 525

Answers (2)

Brian
Brian

Reputation: 118935

(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).

Upvotes: 5

Yin Zhu
Yin Zhu

Reputation: 17119

not an error.

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

Upvotes: 2

Related Questions