Workspaces

RAII-style memory management for C.

Concept & Motivation

One of the biggest criticisms of C is the lack of "Destructors". Camelot introduces the Workspace type to bring RAII (Resource Acquisition Is Initialization) to C. This guarantees that an Arena is released when it goes out of scope.


API Reference

Workspace

Mark an Arena for automatic cleanup.

Workspace scratch = arena.create(u64 size);
  • Mechanism: Uses compiler extensions to inject a release call at the end of the block.

  • Overhead: Zero runtime cost compared to writing the cleanup code manually.

circle-check

Best Practice

Example:

void process_request() {
    // 1. Create a Workspace
    Workspace scratch = arena.create(1024);

    // 2. Allocate and work
    String data = io.slurp(&scratch, "user.json");
    if (data.len == 0) {
        return; // Safe! 'scratch' is released automatically.
    }

    io.print("Processing: %S\n", data);

} // 'scratch' is released here automatically.

Last updated