How to allocate 1MB in Rust

1 Answer

0 votes
fn main() {
    // Allocates 1 MB = 1,048,576 bytes
    
    let buf: Vec<u8> = Vec::with_capacity(1024 * 1024);
    
    println!("{:?}", buf.capacity());
}
 
 
  
/*
run:
  
1048576
  
*/

 



answered May 20, 2025 by avibootz

Related questions

3 answers 418 views
2 answers 330 views
3 answers 363 views
3 answers 415 views
3 answers 398 views
398 views asked May 20, 2025 by avibootz
1 answer 213 views
213 views asked May 20, 2025 by avibootz
...