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 419 views
2 answers 333 views
3 answers 365 views
3 answers 419 views
3 answers 406 views
406 views asked May 20, 2025 by avibootz
1 answer 214 views
214 views asked May 20, 2025 by avibootz
...