Rustアンチスレ (202レス)
Rustアンチスレ http://mevius.5ch.net/test/read.cgi/tech/1509028624/
上
下
前次
1-
新
通常表示
512バイト分割
レス栞
抽出解除
レス栞
143: デフォルトの名無しさん [sage] 2022/05/23(月) 09:11:41.94 ID:n2ZPTBPD // ヒープを使う型Testを作って実証実験 #[derive(Debug)] struct Test(Box<isize>); // Test型が作成される時に使われるnew()を実装 impl Test { fn new(n: isize) -> Self { let new = Test(Box::new(n)); // その時にヒープで確保されたアドレスを表示 println!("{:p} = Test::new({n})", new.0); new } } // Test型の足し算を実装 impl std::ops::Add for Test { type Output = Self; fn add(self, rhs: Self) -> Self::Output { Test::new(*self.0 + *rhs.0) } } // 足し算の途中で使われる一時領域のアドレスはどうなるか? fn main() { let a = Test::new(1); let b = Test::new(10); let c = Test::new(100); let d = Test::new(1000); let e = Test::new(10000); println!("{:?}", a + b + c + d + e); } http://mevius.5ch.net/test/read.cgi/tech/1509028624/143
152: デフォルトの名無しさん [sage] 2022/05/23(月) 16:28:21.49 ID:wuIMUAe9 試しに>>143で中間値をもう一つ必要とする例でやってみた println!("{:?}", (a + b) + (c + d) + e); メモリ1 = Test::new(1) メモリ2 = Test::new(10) メモリ3 = Test::new(100) メモリ4 = Test::new(1000) メモリ5 = Test::new(10000) メモリ6 = Test::new(11) // (a + b) メモリ1 = Test::new(1100) // (c + d) メモリ3 = Test::new(1111) // (a + b) + (c + d) メモリ6 = Test::new(11111) // (a + b) + (c + d) + e 即座に解放された変数領域を2つ使う点で異なるが結果的に計6つ使用に収まっているな http://mevius.5ch.net/test/read.cgi/tech/1509028624/152
メモ帳
(0/65535文字)
上
下
前次
1-
新
書
関
写
板
覧
索
設
栞
歴
スレ情報
赤レス抽出
画像レス抽出
歴の未読スレ
AAサムネイル
Google検索
Wikipedia
ぬこの手
ぬこTOP
0.767s*