Allocator.dupe(arg) ᴾᴴᴾ - chung-leong/zigar GitHub Wiki

JavaScript | PHP


Allocate memory and copy contents of the given object into it.

Usage

const std = @import("std");

var gpa = std.heap.DebugAllocator(.{}).init;
pub const allocator = gpa.allocator();
pub const Point = struct {
    x: i32,
    y: i32,
};
<?php

$m = zigar_use(__DIR__ . '/allocator-js-example-2.zig');

$buf1 = $m->allocator->dupe('Hello world');
$m->allocator->free($buf1);
$buf2 = $m->allocator->dupe(new ArrayBuffer(128));
$m->allocator->free($buf2);
$array = $m->allocator->dupe(new Int32Array([ 1, 2, 3, 4 ]));
$m->allocator->free($array);

Arguments:

  • arg
    A string, an ArrayBuffer or a typed array (Uint8Array, Int32Array, etc.)

Return value:

ArrayBuffer or typed array