Пример #1
0
        internal static string GetBuildInfoString(GetBuildInfoDelegate method, IntPtr program, IntPtr device, uint name)
        {
            IntPtr    size;
            ErrorCode error = method(program, device, name, IntPtr.Zero, IntPtr.Zero, out size);

            if (error != ErrorCode.Success)
            {
                throw new OpenClException(error);
            }
            string result = null;
            IntPtr buf    = Marshal.AllocHGlobal(size);

            try {
                error = method(program, device, name, size, buf, out size);
                if (error != ErrorCode.Success)
                {
                    throw new OpenClException(error);
                }
                result = Marshal.PtrToStringAnsi(buf);
            }
            finally {
                Marshal.FreeHGlobal(buf);
            }
            return(result);
        }
Пример #2
0
        internal static T GetBuildInfo <T> (GetBuildInfoDelegate method, IntPtr program, IntPtr device, uint name) where T : struct
        {
            IntPtr size;
            T      result = default(T);
            var    h      = GCHandle.Alloc(result, GCHandleType.Pinned);

            try {
                ErrorCode error = method(program, device, name, (IntPtr)Marshal.SizeOf <T> (), h.AddrOfPinnedObject(), out size);
                if (error != ErrorCode.Success)
                {
                    throw new OpenClException(error);
                }
            } finally {
                h.Free();
            }
            return(result);
        }
Пример #3
0
        internal static T GetBuildInfoEnum <T> (GetBuildInfoDelegate method, IntPtr program, IntPtr device, uint name) where T : struct
        {
            var type   = Enum.GetUnderlyingType(typeof(T));
            var result = Activator.CreateInstance(type);
            var size   = (IntPtr)Marshal.SizeOf(type);
            var h      = GCHandle.Alloc(result, GCHandleType.Pinned);

            try {
                ErrorCode error = method(program, device, name, size, h.AddrOfPinnedObject(), out size);
                if (error != ErrorCode.Success)
                {
                    throw new OpenClException(error);
                }
            } finally {
                h.Free();
            }
            return((T)result);
        }