Allocator.dupe(arg) - chung-leong/zigar GitHub Wiki
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,
};
import { allocator, Point } from './allocator-js-example-2.zig';
const dv1 = allocator.dupe('Hello world');
allocator.free(dv1);
const dv2 = allocator.dupe(new DataView(new ArrayBuffer(128)));
allocator.free(dv2);
const dv3 = allocator.dupe(new Int32Array([ 1, 2, 3, 4 ]));
allocator.free(dv3);
const point = allocator.dupe(new Point({ x: 1, y: 2 }));
allocator.free(point);
Arguments:
arg
Astring
, a Zig object, or any other ArrayBuffer-backed object (DataView
,Uint8Array
,Buffer
, etc.)
Return value:
DataView
or Zig object