Hello Arrayfire team!,
I was curious about the implemented APIs for dotnet so far and noticed that there is one is missing (or commented out) : "af_get_raw_ptr".
When using arrayfire you just always get the "unmanaged" C++ af array object as an IntrPtr without any possibility to use this object in other .NET APIs (except arrayfire). In my opinion it would be awesome if .NET would have the underlying array as dotnet object but without duplicating it in memory (this means the raw pointer as .NET array or Span or sth in this way).
If arrayfire-dotnet could do this - you could interact with many other librarties but do not duplicate the memory (as long as on CPU backend I guess).
For this the API af_get_raw_ptr is important. I did some ... try outs and played around with it. I was able to create an arrayfire array, got the raw pointer and created a span object from it. Just want to share with you and ask what you think about. unfortunately until now I did not test if there is really not a duplicate in memory and it was for a very small array so far... plus a lot of unsafe sections
publicstaticclassaf{[DllImport("afcpu.dll",ExactSpelling=true,SetLastError=false,CallingConvention=CallingConvention.Cdecl)]publicstaticexternintaf_create_array(outIntPtrarray_arr,[In]float[]data,uintndims,[In]long[]dim_dims,inttype);[DllImport("afcpu.dll")]publicunsafestaticexternintaf_get_raw_ptr(void**ptr,IntPtrarr);}classProgram{staticunsafevoidMain(string[]args){float[]dotnetArray={101,2,3,4,5};floatpuffer_1=5;IntPtraf_Ptr=newIntPtr();void*puffer_2=(void*)&puffer_1;void**raw_ptr=&puffer_2;interror=af.af_create_array(outaf_Ptr,dotnetArray,1,newlong[]{5},0);error=af.af_get_raw_ptr(raw_ptr,af_Ptr);puffer_2=*raw_ptr;vardotnetSpan=newSpan<float>((float*)puffer_2,5);}}
Hello Arrayfire team!,
I was curious about the implemented APIs for dotnet so far and noticed that there is one is missing (or commented out) : "af_get_raw_ptr".
When using arrayfire you just always get the "unmanaged" C++ af array object as an IntrPtr without any possibility to use this object in other .NET APIs (except arrayfire). In my opinion it would be awesome if .NET would have the underlying array as dotnet object but without duplicating it in memory (this means the raw pointer as .NET array or Span or sth in this way).
If arrayfire-dotnet could do this - you could interact with many other librarties but do not duplicate the memory (as long as on CPU backend I guess).
For this the API af_get_raw_ptr is important. I did some ... try outs and played around with it. I was able to create an arrayfire array, got the raw pointer and created a span object from it. Just want to share with you and ask what you think about. unfortunately until now I did not test if there is really not a duplicate in memory and it was for a very small array so far... plus a lot of unsafe sections