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

1 answer 147 views
3 answers 255 views
2 answers 214 views
3 answers 221 views
3 answers 239 views
3 answers 259 views
259 views asked May 20, 2025 by avibootz
...