add realloc (and update c_allocator)
This commit is contained in:
@@ -627,9 +627,10 @@
|
||||
parameters
|
||||
|
||||
25. dynamic heap allocation (implemented; v1)
|
||||
- `std/mem` exposes a plain-data `Allocator` contract with `?*mut anyopaque` context, `alloc`, and `free` `@func` pointers
|
||||
- `std/mem` exposes a plain-data `Allocator` contract with `?*mut anyopaque` context and `alloc`, `realloc`, and `free` `@func` pointers
|
||||
- `mem.c_allocator` is the libc-backed allocator; `mem.alloc(mem.c_allocator, size, alignment)` returns nullable mutable byte memory
|
||||
- `mem.free(mem.c_allocator, ptr, size, alignment)` frees with the same allocator; `malloc` handles default-aligned requests and `posix_memalign` handles larger power-of-two alignments
|
||||
- `mem.realloc` preserves alignment and the original allocation on failure; zero size frees, and over-aligned blocks use allocate/copy/free
|
||||
- typed allocation helpers, arenas/pools, build-mode heap policy, and escaping-allocation diagnostics remain deferred
|
||||
|
||||
26. import from project "root" (implemented)
|
||||
@@ -718,7 +719,7 @@
|
||||
- native function pointers are non-variadic v1; C variadic function pointers stay
|
||||
under `*c_func(...) R`
|
||||
|
||||
28. brolang build system — v0 shipped
|
||||
28. brolang build system (implemented; v0 shipped)
|
||||
- `brolang build [root]` reads a declarative `config` constant from
|
||||
`root/build.bro` (importing `@std/build`'s `BuildConfig`) and compiles the
|
||||
program package it names. The config is read from the checked HIR — build.bro
|
||||
@@ -1397,7 +1398,7 @@ Memory allocation in Brolang is designed to be **explicit but not verbose**. We
|
||||
Brolang provides a libc-backed allocator value:
|
||||
|
||||
* Available as `mem.c_allocator`
|
||||
* Passed explicitly to `mem.alloc` and `mem.free`
|
||||
* Passed explicitly to `mem.alloc`, `mem.realloc`, and `mem.free`
|
||||
* **Immutable at runtime** — cannot be reconfigured
|
||||
|
||||
```
|
||||
@@ -1595,6 +1596,7 @@ main func() void {
|
||||
| What | How | When to Use |
|
||||
| -- | -- | -- |
|
||||
| `mem.alloc(mem.c_allocator, n, a)` | Libc-backed allocator | General purpose byte allocation |
|
||||
| `mem.realloc(mem.c_allocator, ptr, old_n, new_n, a)` | Libc-backed allocator | Resize while preserving alignment and up to `min(old_n, new_n)` bytes |
|
||||
| `mem.free(mem.c_allocator, ptr, n, a)` | Libc-backed allocator | Free byte allocation with original size/alignment |
|
||||
| `mem.alloc(allocator, n, a)` | Caller-provided allocator | Escaping allocations (returned or written to caller's data) |
|
||||
| typed helpers / arenas / pools | Future APIs | Higher-level allocation patterns |
|
||||
|
||||
Reference in New Issue
Block a user