Skip to content

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 0

There 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) -> ptr
extern func free(p: ptr) -> void
func main() -> i32:
let buf = malloc(1024)
free(buf)
return 0

Memory 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 0

This 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) -> ptr
extern func free(p: ptr) -> void
func main() -> i32:
let buf = malloc(1024)
free(buf)
return 0

What does not exist

FeatureStatus
std/core.tgnot present
std/list.tgnot present
List structnot present
StringBuildernot present
fs.close / list.disposenot present
string + operatornot implemented