Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Rust

Idiom #88 Allocate 1M bytes

Create a new bytes buffer buf of size 1,000,000.

let buf: Vec<u8> = Vec::with_capacity(1000000);

This creates a simple but fast vector. There is also the unstable alloc::heap::allocate if you want to go more low-level.
type Byte is range 0 .. 255
  with Size => 8;
      
type Byte_Array is array (Positive range <>) of Byte;  
      
Buf : Byte_Array (1 .. 1_000_000);

New implementation...
< >
programming-idioms.org