検索

phrase: max: clip:
target: order:
Results of 1 - 10 of about 12 for cap (0.023 sec.)
RawVec 12416
はじめに 1. 安全と危険のご紹介 1.1. 安全と危険の相互作用 1.2. Unsafe と連携する 2. データレイアウ ... たので、今がロジックを圧縮する丁度良い時です。 (ptr, cap) のペアを取り除き、これにアロケート、伸長そして解放 ... ックを 与えます。 struct RawVec<T> { ptr: Unique<T>, cap: usize, } impl<T> RawVec<T> { fn new() -> Self { a ... RawVec { ptr: Unique::new(heap::EMPTY as *mut T), cap: 0 } } } // Vec の時と変更ありません fn grow(&mut ... >(); let elem_size = mem::size_of::<T>(); let (new_cap, ptr) = if self.cap == 0 { let ptr = heap::allocat ...
https://man.plustar.jp/rust/nomicon/vec-raw.html - [similar]
Final Code 11603
はじめに 1. 安全と危険のご紹介 1.1. 安全と危険の相互作用 1.2. Unsafe と連携する 2. データレイアウ ... se alloc::heap; struct RawVec<T> { ptr: Unique<T>, cap: usize, } impl<T> RawVec<T> { fn new() -> Self { u ... his branch should be stripped at compile time. let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 }; / ... RawVec { ptr: Unique::new(heap::EMPTY as *mut T), cap: cap } } } fn grow(&mut self) { unsafe { let elem_ ... size = mem::size_of::<T>(); // since we set the capacity to usize::MAX when elem_size is // 0, getting ...
https://man.plustar.jp/rust/nomicon/vec-final.html - [similar]
サイズが 0 の型を扱う 10312
はじめに 1. 安全と危険のご紹介 1.1. 安全と危険の相互作用 1.2. Unsafe と連携する 2. データレイアウ ... 。この分岐はコンパイル時に取り除かれるはずです。 let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 }; / ... RawVec { ptr: Unique::new(heap::EMPTY as *mut T), cap: cap } } } fn grow(&mut self) { unsafe { let elem_ ... を必然的に // 意味します。 assert!(elem_size != 0, "capacity overflow"); let align = mem::align_of::<T>(); ... let (new_cap, ptr) = if self.cap == 0 { let ptr = heap::allocat ...
https://man.plustar.jp/rust/nomicon/vec-zsts.html - [similar]
アロケーティング 9975
はじめに 1. 安全と危険のご紹介 1.1. 安全と危険の相互作用 1.2. Unsafe と連携する 2. データレイアウ ... っ込みましょう! これは全く問題ありません。なぜなら、 cap == 0 が既に、アロケーションが ないことを示す番兵と ... ありません。なぜならほとんどすべてのコードで、結局は cap > len か len > 0 を 通常確かめる必要があるからです ... { ptr: Unique::new(heap::EMPTY as *mut _), len: 0, cap: 0 } } } } コードの中に、assert を入れました。サイ ... ます。欲しい ロジックは大体以下のようなものです。 if cap == 0: allocate() cap = 1 else: reallocate() cap *= ...
https://man.plustar.jp/rust/nomicon/vec-alloc.html - [similar]
IntoIter 9162
はじめに 1. 安全と危険のご紹介 1.1. 安全と危険の相互作用 1.2. Unsafe と連携する 2. データレイアウ ... っていきます。 struct IntoIter<T> { buf: Unique<T>, cap: usize, start: *const T, end: *const T, } そしてこ ... め、 Vec を分配出来ません。 let ptr = self.ptr; let cap = self.cap; let len = self.len; // Vec をドロップす ... 。 mem::forget(self); unsafe { IntoIter { buf: ptr, cap: cap, start: *ptr, end: if cap == 0 { // このポイン ... rop for IntoIter<T> { fn drop(&mut self) { if self.cap != 0 { // 残っている要素を全てドロップします for _ ...
https://man.plustar.jp/rust/nomicon/vec-into-iter.html - [similar]
デアロケーティング 8260
はじめに 1. 安全と危険のご紹介 1.1. 安全と危険の相互作用 1.2. Unsafe と連携する 2. データレイアウ ... しません (今回はコードが取り除かれています) 。 self.cap == 0 である場合、 heap::deallocate を呼んではいけま ... <T> Drop for Vec<T> { fn drop(&mut self) { if self.cap != 0 { while let Some(_) = self.pop() { } let alig ... ::size_of::<T>(); let num_bytes = elem_size * self.cap; unsafe { heap::deallocate(*self.ptr as *mut _, nu ... フタイム , メモリ , self , Drop , let , pop , 実装 , cap , コード ...
https://man.plustar.jp/rust/nomicon/vec-dealloc.html - [similar]
Unsafe と連携する 8012
はじめに 1. 安全と危険のご紹介 1.1. 安全と危険の相互作用 1.2. Unsafe と連携する 2. データレイアウ ... さい。 pub struct Vec<T> { ptr: *mut T, len: usize, cap: usize, } // この実装ではサイズが 0 の型を正しく扱 ... fn push(&mut self, elem: T) { if self.len == self.cap { // この例では重要ではありません。 self.reallocat ... room(&mut self) { // キャパシティを大きくする self.cap += 1; } このコードは 100% 安全な Rust ですが、同時 ... 不健全です。 キャパシティの変更は、Vec の普遍条件( cap は Vec にアロケートされたスペースを表している)を破 ...
https://man.plustar.jp/rust/nomicon/working-with-unsafe.html - [similar]
PhantomData 7481
はじめに 1. 安全と危険のご紹介 1.1. 安全と危険の相互作用 1.2. Unsafe と連携する 2. データレイアウ ... ata: *const T, // *const for variance! len: usize, cap: usize, } Unlike the previous example, it appears ... a: *const T, // *const for covariance! len: usize, cap: usize, _marker: marker::PhantomData<T>, } Raw poi ...
https://man.plustar.jp/rust/nomicon/phantom-data.html - [similar]
レイアウト 7340
はじめに 1. 安全と危険のご紹介 1.1. 安全と危険の相互作用 1.2. Unsafe と連携する 2. データレイアウ ... うことになります。 pub struct Vec<T> { ptr: *mut T, cap: usize, len: usize, } fn main() {} そして実際に、こ ... Unique, self}; pub struct Vec<T> { ptr: Unique<T>, cap: usize, len: usize, } fn main() {} もしヌルポインタ ...
https://man.plustar.jp/rust/nomicon/vec-layout.html - [similar]
print.html 7198
はじめに 1. 安全と危険のご紹介 1.1. 安全と危険の相互作用 1.2. Unsafe と連携する 2. データレイアウ ... さい。 pub struct Vec<T> { ptr: *mut T, len: usize, cap: usize, } // この実装ではサイズが 0 の型を正しく扱 ... fn push(&mut self, elem: T) { if self.len == self.cap { // この例では重要ではありません。 self.reallocat ... room(&mut self) { // キャパシティを大きくする self.cap += 1; } このコードは 100% 安全な Rust ですが、同時 ... 不健全です。 キャパシティの変更は、Vec の普遍条件( cap は Vec にアロケートされたスペースを表している)を破 ...
https://man.plustar.jp/rust/nomicon/print.html - [similar]
PREV 1 2 NEXT