Memory & String Runtime
Memory & String Runtime
Overview
Thagore uses a managed string runtime with manual memory management for raw pointers. There is no garbage collector.
String Management
Strings are the str type. String literals are stored as constants in the compiled binary. The runtime manages concatenated strings automatically — you do not need to free them manually.
To concatenate strings, use std.string.concat:
import std.string as string
func greet(name: str) -> str: return string.concat("Hello, ", name)
func main() -> i32: println(greet("World")) return 0There is no + operator on strings in the language.
Raw pointer operations
The ptr type is a raw pointer (equivalent to void* in C). Use extern func to access memory operations:
extern func malloc(size: i32) -> ptrextern func free(p: ptr) -> void
func main() -> i32: let buf = malloc(1024) free(buf) return 0Memory testing pattern
To verify a program does not crash from memory issues:
import std.string as string
func make_label(n: i32) -> str: return string.concat("item-", string.from_int(n))
func main() -> i32: let i: i32 = 0 while (i < 1000): let label = make_label(i) println(label) i = i + 1 return 0This pattern tests that repeated string allocations do not crash the runtime.
Null pointer pattern
Use extern func to get and check null pointers:
extern func malloc(size: i32) -> ptrextern func free(p: ptr) -> void
func main() -> i32: let buf = malloc(1024) free(buf) return 0What does not exist
| Feature | Status |
|---|---|
std/core.tg | not present |
std/list.tg | not present |
List struct | not present |
StringBuilder | not present |
fs.close / list.dispose | not present |
string + operator | not implemented |