Guest User

Untitled

a guest
Jun 25th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #![feature(try_reserve)]
  2. use std::collections::CollectionAllocErr;
  3.  
  4. fn allocate_byte_array(len: usize) -> Result<Vec<u8>, CollectionAllocErr> {
  5. let mut v = Vec::new();
  6. v.try_reserve(len)?;
  7. unsafe {
  8. v.set_len(len);
  9. }
  10. Ok(v)
  11. }
  12.  
  13. fn main() {
  14. let mut v = allocate_byte_array(1024*1024*1024*100).unwrap();
  15. println!("size {}", v.len());
  16. let mut i = 1024*1024+5;
  17. v[i] = 3;
  18. println!("byte #{} is {}", i, v[i]);
  19. i = 1024*1024*1024*100-1;
  20. println!("byte #{} is {}", i, v[i]);
  21. }
Add Comment
Please, Sign In to add comment