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 149 views
3 answers 259 views
2 answers 219 views
3 answers 225 views
3 answers 242 views
3 answers 261 views
261 views asked May 20, 2025 by avibootz
...