Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. // NOTE: Don't run this in the playground if the allocation is huge
  2. // use the `...` button and view assembly only.
  3.  
  4. extern crate crossbeam; // 0.7.2
  5. use crossbeam::atomic::AtomicCell;
  6.  
  7. fn main() {
  8. // call is required to avoid dead-code elimination
  9. // norun();
  10. }
  11.  
  12. fn norun() {
  13. const MAX_VOCAB: usize = 2 << 28;
  14. let mut wordidx: Vec<AtomicCell<Option<u32>>> =
  15. Vec::with_capacity(MAX_VOCAB); wordidx.resize_with(MAX_VOCAB, || AtomicCell::new(None));
  16.  
  17. // compiler trick to ensure the assembly is actually emitted:
  18. // because the address of the allocation is displayed, the optimizer
  19. // assumes that it actually has to write to the allocated memory.
  20. // See the llvm docs for `nocapture` attribute and Wikipedia
  21. // "Escape Analysis" for more.
  22. println!("{:p}", wordidx.as_ptr());
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement