rust [rust] Rust 요약(메모리 관리)
2023.05.10 18:28
[rust] Rust 요약(메모리 관리)
Rust 요약(메모리 관리)
Rust 는 꽤 독특한 메모리 관리 시스템을 가지고 있다.
소유권
소유권 참조
메모리 할당
/// A macro similar to `vec![$elem; $size]` which returns a boxed array.
///
/// ```rustc
/// let _: Box<[u8; 1024]> = box_array![0; 1024];
/// ```
macro_rules! box_array {
($val:expr ; $len:expr) => {{
// Use a generic function so that the pointer cast remains type-safe
fn vec_to_boxed_array<T>(vec: Vec<T>) -> Box<[T; $len]> {
let boxed_slice = vec.into_boxed_slice();
let ptr = ::std::boxed::Box::into_raw(boxed_slice) as *mut [T; $len];
unsafe { Box::from_raw(ptr) }
}
vec_to_boxed_array(vec![$val; $len])
}};
}
fn main() {
const LEN: usize = 10_000_000;
let _huge_heap_array: Box<[u8; LEN]> = box_array![0; LEN];
}
[출처] https://www.skyer9.pe.kr/wordpress/?p=5636
본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
댓글 0
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
|---|---|---|---|---|
| 5 |
[go golang] Gin 소개 & 설치 (Introduction & Installation)
| 졸리운_곰 | 2023.01.03 | 182 |
| 4 |
[go golang] Golang REST API 만들기
| 졸리운_곰 | 2023.01.03 | 107 |
| 3 |
[go golang] A Quick / Short Example of using TFLite with Golang and a GANs Model
| 졸리운_곰 | 2022.11.29 | 157 |
| 2 | [go golang] Web Development with Go (Golang) | 졸리운_곰 | 2022.11.29 | 156 |
| 1 |
[go golang] Golang Machine Learning
| 졸리운_곰 | 2022.11.28 | 216 |

