Logo

Programming-Idioms

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

Idiom #88 Allocate 1M bytes

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

$memStart = memory_get_usage();
$buf = str_repeat("\x00", 1000 * 1000);
$memEnd = memory_get_usage();
echo $memEnd - $memStart, PHP_EOL;

$buf is a string filled with 1 million NUL bytes. Also shows how much was used in the end.
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