@@ -8,7 +8,8 @@ import AllocatorsAlloc from "!!raw-loader!./01.allocators-alloc.zig";
88import AllocatorsFba from " !!raw-loader!./01.allocators-fba.zig" ;
99import AllocatorsArena from " !!raw-loader!./01.allocators-arena.zig" ;
1010import AllocatorsCreate from " !!raw-loader!./01.allocators-create.zig" ;
11- import AllocatorsGpa from " !!raw-loader!./01.allocators-gpa.zig" ;
11+ import AllocatorsDebug from " !!raw-loader!./01.allocators-debug.zig" ;
12+ import AllocatorsSmp from " !!raw-loader!./01.allocators-smp.zig" ;
1213
1314# Allocators
1415
@@ -17,7 +18,7 @@ the programmer to choose precisely how memory allocations are done within the
1718standard library - no allocations happen behind your back in the standard
1819library.
1920
20- The most basic allocator is
21+ The most fundamental allocator is
2122[ ` std.heap.page_allocator ` ] ( https://ziglang.org/documentation/master/std/#std.heap.page_allocator ) .
2223Whenever this allocator makes an allocation, it will ask your OS for entire
2324pages of memory; an allocation of a single byte will likely reserve multiple
@@ -50,18 +51,24 @@ once. Here, `.deinit()` is called on the arena, which frees all memory. Using
5051
5152<CodeBlock language = " zig" >{ AllocatorsCreate } </CodeBlock >
5253
53- The Zig standard library also has a general-purpose allocator. This is a safe
54+ The Zig standard library also has a general-purpose debug allocator. This is a safe
5455allocator that can prevent double-free, use-after-free and can detect leaks.
5556Safety checks and thread safety can be turned off via its configuration struct
56- (left empty below). Zig's GPA is designed for safety over performance, but may
57+ (left empty below). Zig's DebugAllocator is designed for safety over performance, but may
5758still be many times faster than page_allocator.
5859
59- <CodeBlock language = " zig" >{ AllocatorsGpa } </CodeBlock >
60+ <CodeBlock language = " zig" >{ AllocatorsDebug } </CodeBlock >
6061
61- For high performance (but very few safety features!),
62- [ ` std.heap.c_allocator ` ] ( https://ziglang.org/documentation/master/std/#std.heap.c_allocator )
63- may be considered. This,however, has the disadvantage of requiring linking Libc,
64- which can be done with ` -lc ` .
62+ For high performance (but very few safety features!), the Zig standard library offers
63+ [ ` std.heap.SmpAllocator ` ] ( https://ziglang.org/documentation/master/std/#std.heap.SmpAllocator ) .
64+ This is a general-purpose allocator designed for [ maximum performance] ( https://ziglang.org/download/0.14.0/release-notes.html#SmpAllocator )
65+ on multithreaded machines.
66+
67+ <CodeBlock language = " zig" >{ AllocatorsSmp } </CodeBlock >
68+
69+ As an alternative when SmpAllocator is not available or desired, the libc allocator
70+ [ ` std.heap.c_allocator ` ] ( https://ziglang.org/documentation/master/std/#std.heap.c_allocator ) may be considered.
71+ This, however, has the disadvantage of requiring linking Libc, which can be done with ` -lc ` .
6572
6673Benjamin Feng's talk
6774[ _ What's a Memory Allocator Anyway?_ ] ( https://www.youtube.com/watch?v=vHWiDx_l4V0 )
0 commit comments