From b46ae6f6e943d742f6e7d7b19cdeb526bf0ad7f0 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Wed, 10 Jun 2026 03:04:20 +0200 Subject: [PATCH] Allocations --- content/docs/components/classes.mdx | 14 ++++++++++++++ content/docs/components/pointers-references.mdx | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/content/docs/components/classes.mdx b/content/docs/components/classes.mdx index 702e191..cb0ed2e 100644 --- a/content/docs/components/classes.mdx +++ b/content/docs/components/classes.mdx @@ -111,6 +111,20 @@ pub class Container { } ``` +## Allocations +In classes, it's very important to initialize heap allocated fields in `constructor` using `path -> expr`, here is the most common example: +```mist +pub class Dog : Animal { + pub heap_alloc Box; + + constructor() { + super -> Super::new(); + self.heap_alloc -> Box::new(69); + } +} +``` +This outputs `std::ptr::write` which is a force write to memory without dropping what "exists", and it's commonly used in uninitialized memory, such as uninitialized dynamic fields. + ## Key Characteristics - **Unified Scope**: Data and behavior live in one class block. diff --git a/content/docs/components/pointers-references.mdx b/content/docs/components/pointers-references.mdx index b8d0dfd..bade751 100644 --- a/content/docs/components/pointers-references.mdx +++ b/content/docs/components/pointers-references.mdx @@ -40,6 +40,17 @@ pub struct Inspector<'a> { } ``` +## Allocations +In classes, it's very important to initialize heap allocated fields in `constructor` using `path -> expr`, here is the most common example: +```mist +pub class Dog : Animal { + constructor() { + super -> Super::new(); + } +} +``` +This outputs `std::ptr::write` which is a force write to memory without dropping what "exists", and it's commonly used in uninitialized memory, such as uninitialized dynamic fields. + ## Key Characteristics - **Prefix Pointer Syntax**: `*Type` for shared references, `*mut Type` for mutable references.