internal static Who[] NativeGet(Sigar sigar) { System.Type typeFromHandle = typeof(WhoList); System.IntPtr intPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(typeFromHandle)); int num = WhoList.sigar_who_list_get(sigar.sigar.Handle, intPtr); if (num != 0) { System.Runtime.InteropServices.Marshal.FreeHGlobal(intPtr); throw Sigar.FindException(sigar, num); } WhoList whoList = (WhoList)System.Runtime.InteropServices.Marshal.PtrToStructure(intPtr, typeFromHandle); Who[] array = new Who[whoList.Number]; System.IntPtr ptr = whoList.data; int num2 = System.Runtime.InteropServices.Marshal.SizeOf(array[0]); int num3 = 0; while ((long)num3 < (long)((ulong)whoList.Number)) { array[num3] = (Who)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr, typeof(Who)); ptr = Sigar.incrementIntPtr(ptr, num2); num3++; } WhoList.sigar_who_list_destroy(sigar.sigar.Handle, intPtr); System.Runtime.InteropServices.Marshal.FreeHGlobal(intPtr); return(array); }
internal static FileSystem[] NativeGet(Sigar sigar) { Type type = typeof(FileSystemList); IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type)); int status = sigar_file_system_list_get(sigar.sigar.Handle, ptr); if (status != Sigar.OK) { Marshal.FreeHGlobal(ptr); throw Sigar.FindException(sigar, status); } FileSystemList fsPtr = (FileSystemList)Marshal.PtrToStructure(ptr, type); FileSystem[] fs = new FileSystem[fsPtr.Number]; IntPtr fptr = fsPtr.data; int size = Marshal.SizeOf(fs[0]); for (int i = 0; i < fsPtr.Number; i++) { fs[i] = (FileSystem)Marshal.PtrToStructure(fptr, typeof(FileSystem)); //fptr += sizeof(sigar_fs_t); fptr = Sigar.incrementIntPtr(fptr, size); } sigar_file_system_list_destroy(sigar.sigar.Handle, ptr); Marshal.FreeHGlobal(ptr); return(fs); }
internal static CpuInfo[] NativeGet(Sigar sigar) { Type type = typeof(CpuInfoList); IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type)); int status = sigar_cpu_info_list_get(sigar.sigar.Handle, ptr); if (status != Sigar.OK) { Marshal.FreeHGlobal(ptr); throw Sigar.FindException(sigar, status); } CpuInfoList infosPtr = (CpuInfoList)Marshal.PtrToStructure(ptr, type); CpuInfo[] infos = new CpuInfo[infosPtr.Number]; IntPtr eptr = infosPtr.data; int size = Marshal.SizeOf(infos[0]); for (int i = 0; i < infosPtr.Number; i++) { infos[i] = (CpuInfo)Marshal.PtrToStructure(eptr, typeof(CpuInfo)); //eptr += sizeof(sigar_cpu_info_t); eptr = Sigar.incrementIntPtr(eptr, size); } sigar_cpu_info_list_destroy(sigar.sigar.Handle, ptr); Marshal.FreeHGlobal(ptr); return(infos); }