Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(try_reserve)]
- use std::collections::CollectionAllocErr;
- fn allocate_byte_array(len: usize) -> Result<Vec<u8>, CollectionAllocErr> {
- let mut v = Vec::new();
- v.try_reserve(len)?;
- unsafe {
- v.set_len(len);
- }
- Ok(v)
- }
- fn main() {
- let mut v = allocate_byte_array(1024*1024*1024*100).unwrap();
- println!("size {}", v.len());
- let mut i = 1024*1024+5;
- v[i] = 3;
- println!("byte #{} is {}", i, v[i]);
- i = 1024*1024*1024*100-1;
- println!("byte #{} is {}", i, v[i]);
- }
Add Comment
Please, Sign In to add comment