回答編集履歴
1
コメントを受け追記
test
CHANGED
@@ -1,27 +1,69 @@
|
|
1
1
|
`Microsoft.VisualBasic.Devices.ComputerInfo info = new Microsoft.VisualBasic.Devices.ComputerInfo();`を持っているようなので、そこから取れると思います。[C# メモリサイズ、メモリ使用量などを取得する](http://cammy.co.jp/technical/2017/05/23/c-%E3%83%A1%E3%83%A2%E3%83%AA%E3%82%B5%E3%82%A4%E3%82%BA%E3%80%81%E3%83%A1%E3%83%A2%E3%83%AA%E4%BD%BF%E7%94%A8%E9%87%8F%E3%81%AA%E3%81%A9%E3%82%92%E5%8F%96%E5%BE%97%E3%81%99%E3%82%8B/)
|
2
2
|
|
3
|
+
> ``` C#
|
4
|
+
|
5
|
+
> //合計物理メモリ
|
6
|
+
|
7
|
+
> Console.WriteLine("合計物理メモリ:{0}KB", (info.TotalPhysicalMemory/1024));
|
8
|
+
|
9
|
+
> //利用可能な物理メモリ
|
10
|
+
|
11
|
+
> Console.WriteLine("利用可能物理メモリ:{0}KB", (info.AvailablePhysicalMemory/1024));
|
12
|
+
|
13
|
+
> //合計仮想メモリ
|
14
|
+
|
15
|
+
> Console.WriteLine("合計仮想メモリ:{0}KB", (info.TotalVirtualMemory/1024));
|
16
|
+
|
17
|
+
> //利用可能な仮想メモリ
|
18
|
+
|
19
|
+
> Console.WriteLine("利用可能仮想メモリ:{0}KB", (info.AvailableVirtualMemory/1024));
|
20
|
+
|
3
21
|
> ```
|
4
|
-
|
5
|
-
//合計物理メモリ
|
6
|
-
|
7
|
-
Console.WriteLine("合計物理メモリ:{0}KB", (info.TotalPhysicalMemory/1024));
|
8
|
-
|
9
|
-
//利用可能な物理メモリ
|
10
|
-
|
11
|
-
Console.WriteLine("利用可能物理メモリ:{0}KB", (info.AvailablePhysicalMemory/1024));
|
12
|
-
|
13
|
-
//合計仮想メモリ
|
14
|
-
|
15
|
-
Console.WriteLine("合計仮想メモリ:{0}KB", (info.TotalVirtualMemory/1024));
|
16
|
-
|
17
|
-
//利用可能な仮想メモリ
|
18
|
-
|
19
|
-
Console.WriteLine("利用可能仮想メモリ:{0}KB", (info.AvailableVirtualMemory/1024));
|
20
|
-
|
21
|
-
```
|
22
22
|
|
23
23
|
|
24
24
|
|
25
25
|
ヘッダについてはデータの出力前にファイルが存在するか確認して、ファイルが無ければヘッダを出力するようにするのがお手軽だと思います。
|
26
26
|
|
27
27
|
[File.Exists](https://docs.microsoft.com/ja-jp/dotnet/api/system.io.file.exists?view=netframework-4.8)
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
---
|
32
|
+
|
33
|
+
> 'ulong' および 'long' のオペランドの演算子 '/' があいまいです
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
ulongとlongを演算した結果の型は何にすべきか?ulongがulong.MaxValueであり、longが-1の場合、(ulong / long)は-ulong.MaxValueです。これを受け入れられるサイズを持つ整数型はありません。型が決められないのでコンパイラも困ってしまいます。ですので、きちんと型を揃えた状態で計算を実行する必要があります。計算前に型を揃えなければいけない理由は、計算した後、変数に入れるまでの値の扱い(型)をどうするかが決められないからです。(細かい理由は異なると思いますが、そういう風にとらえて問題はないはずです。)
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
``` C#
|
44
|
+
|
45
|
+
int intValue = 1;
|
46
|
+
|
47
|
+
uint uintValue = 2;
|
48
|
+
|
49
|
+
var intRes = uintValue / intValue; // この結果はどう頑張ってもlongの範囲内なのでintResはlong型
|
50
|
+
|
51
|
+
var uintRes = uintValue * uintValue; // この結果はどう頑張ってもulongの範囲内なのでuintResはulong型
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
long longValue = -1;
|
56
|
+
|
57
|
+
ulong ulongValue = ulong.MaxValue;
|
58
|
+
|
59
|
+
var longRes = ulongValue / longValue; // これはどの整数型からもはみ出すのでどうすればいいかわからない!
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
どの型に揃えるかですが、整数型(ulong, long等)は小数値を切り捨ててしまう為、*100する前に一度0か1になってしまいます。
|
68
|
+
|
69
|
+
なので、実数を扱える型にしてください。(doubleあたり?精度を気にするならdecimal?)
|