Allocations

This commit is contained in:
2026-06-10 03:04:20 +02:00
parent dcc1709d9e
commit b46ae6f6e9
2 changed files with 25 additions and 0 deletions
+14
View File
@@ -111,6 +111,20 @@ pub class Container<T> {
} }
``` ```
## 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<i32>;
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 ## Key Characteristics
- **Unified Scope**: Data and behavior live in one class block. - **Unified Scope**: Data and behavior live in one class block.
@@ -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 ## Key Characteristics
- **Prefix Pointer Syntax**: `*Type` for shared references, `*mut Type` for mutable references. - **Prefix Pointer Syntax**: `*Type` for shared references, `*mut Type` for mutable references.