Skip to content

Commit

Permalink
Fixe temp alloc text.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Feb 1, 2025
1 parent 3ddb8ac commit ad598c4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/content/docs/FAQ/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ Regardless of how they are allocated, they can be freed using `free()`

**Q:** How does the temporary allocator work?

**A:** The temporary allocator is a kind of stack allocator. `talloc`, `tcalloc` and `trealloc` correspond to
**A:** The temporary allocator is a kind of stack allocator. `tmalloc`, `tcalloc` and `trealloc` correspond to
`malloc`, `calloc` and `realloc`. There is no `free`, as temporary allocations are free when pool of temporary
objects are released. You use the `@pool()` macro to create a temporary allocation scope. When execution exits
this scope, the temporary objects are all freed:

```c3
@pool()
{
void* some_mem = talloc(128);
void* some_mem = tmalloc(128);
foo(some_mem);
};
// Temporary allocations are automatically freed here.
Expand All @@ -209,9 +209,9 @@ Allocator* temp = allocator::temp();
@pool(temp)
{
// Note, 'allocator::temp() != temp' here!
void* some_mem = talloc(128);
void* some_mem = tmalloc(128);
// Allocate this on the external temp allocator
Foo* foo = temp.new(Foo);
Foo* foo = allocator::new(temp, Foo);
foo.z = foo(some_mem);
// Now "some_mem" will be released,
// but the memory pointed to by "foo" is still valid.
Expand Down

0 comments on commit ad598c4

Please sign in to comment.