Direkte Speicherverwaltung auf Heap-Ebene ohne externe Abhängigkeiten. malloc, calloc und realloc arbeiten mit 8-Byte-Alignment (64-Bit-kompatibel) direkt über libc_malloc. malloc_safe gibt 0 zurück bei OOM; malloc_orpanic beendet das Programm mit einem Fehlercode. Die Unit ist die Grundlage aller dynamischen Datenstrukturen in der Standardbibliothek.
Einsatzbereiche: systemnahe Lyx-Programme, alle Units die dynamisch Speicher verwalten (Listen, Puffer, Strings), sowie eigene Allokatorimplementierungen.
Autor: Andreas Röne
Copyright: 2024-2025 Andreas Röne
| Name | Typ | Wert | Sichtbarkeit |
|---|---|---|---|
ALIGNMENT | int64 | 8 | pub |
ERR_ALLOC_OK | int64 | 0 | pub |
ERR_ALLOC_OOM | int64 | 1 | pub |
ERR_ALLOC_INVALID | int64 | 2 | pub |
ERR_ALLOC_ALIGN | int64 | 3 | pub |
| Signatur | Beschreibung |
|---|---|
libc_malloc(size: int64): int64 | Allociert Rohspeicher über libc-Heap |
libc_free(ptr: int64): int64 | Gibt libc-Heapspeicher frei |
libc_realloc(ptr: int64, size: int64): int64 | Vergrößert oder verkleinert Heapblock |
| Signatur | Sichtbarkeit | Beschreibung |
|---|---|---|
align_to_8(size: int64): int64 | priv | Rundet Größe auf 8-Byte-Grenze auf |
malloc(size: int64): int64 | pub | Allociert ausgerichteten Heapspeicher |
calloc(count: int64, elem_size: int64): int64 | pub | Allociert nullinitialisierten Speicherblock |
free_mem(ptr: int64): int64 | pub | Gibt Heapblock frei |
realloc_mem(ptr: int64, new_size: int64): int64 | pub | Ändert Größe eines Heapblocks |
size_of_int64(): int64 { return 8; } | pub | Gibt Byte-Größe von int64 zurück |
size_of_ptr(): int64 { return 8; } | pub | Gibt Byte-Größe eines Zeigers zurück |
is_aligned(ptr: int64): bool | pub | Prüft 8-Byte-Ausrichtung des Zeigers |
malloc_safe(size: int64): int64 | pub | Allociert Speicher, gibt 0 bei OOM |
malloc_orpanic(size: int64): int64 | pub | Allociert Speicher oder beendet Programm |