Logo

Programming-Idioms

  • D
  • Erlang
  • C#
  • C

Idiom #88 Allocate 1M bytes

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

#include <stdlib.h>
void *buf = malloc(1000000);
import std.c.stdlib;
import core.memory;
void[] buf = malloc(1024 * 1024)[0..1024 * 1024];

GC-free heap
import std.c.stdlib;
import core.memory;
void[] buf = GC.malloc(1024 * 1024)[0..1024 * 1024];

GC heap
var buf = new byte[1000000];
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