Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Idea about the missing API af_get_raw_ptr

Đang mở
#25 5 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
api

Hướng nghiên cứu

Issue không nêu tên tệp nào trong repository hoặc các bài kiểm thử. Hãy bắt đầu bằng việc xem xét các khai báo interop C# được cung cấp và hợp đồng API ArrayFire af_get_raw_ptr, sau đó xác định các yêu cầu về quyền sở hữu và vòng đời được hỗ trợ. Công việc được xem là hoàn tất khi đã thống nhất một thiết kế truy cập dành cho .NET bằng raw pointer hoặc zero-copy, kèm theo việc xác thực rằng vùng nhớ được exposed vẫn hợp lệ mà không cần sao chép.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

public static class af
    {
        [DllImport("afcpu.dll", ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
		public static extern int af_create_array(out IntPtr array_arr, [In] float[] data, uint ndims, [In] long[] dim_dims, int type);
        [DllImport("afcpu.dll")]
        public unsafe static extern int af_get_raw_ptr(void** ptr, IntPtr arr);
    }
    class Program
    {
        static unsafe void Main(string[] args)
        {
            float[] dotnetArray = {101,2,3,4,5};

            float puffer_1 = 5;

            IntPtr af_Ptr = new IntPtr();

            void* puffer_2=(void*) &puffer_1;

            void** raw_ptr = & puffer_2;
            
            int error = af.af_create_array(out af_Ptr, dotnetArray, 1,new long[] {5},0 );

            error = af.af_get_raw_ptr(raw_ptr,af_Ptr);

            puffer_2 = *raw_ptr;

            var dotnetSpan = new Span<float>((float*)puffer_2, 5); 

        }
    }
Ngôn ngữ chính
C#
Star
76
Fork
19
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của arrayfire/arrayfire-dotnet

Tất cả issue của arrayfire/arrayfire-dotnet

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.