On this page
article
Allocator
Module: std/allocator
The allocator module provides the Allocator interface, which describes the functionality
of allocators used in Violet.
Definition
This is the public allocator interface, which users derive an allocator from directly.
Allocators can implement this interface and be used for all forms of memory allocation.
interface Allocator {
-- Create a new pointer of type
fn create[T](self: *Self): !*T;
-- Create a new buffer of type with n elements
fn alloc(self: *Self, n: usize): []T;
-- Destroy an allocated type
fn destroy[T](self: *Self, value: *T);
-- Destroy an allocated buffer
fn free[T](self: *Self, value: []T);
-- Resize an existing allocation
fn resize[T](self: *Self, value: T, new_size: usize): bool;
}