by alchemio · 2y ago · 0 comments
Similarly zig’s stdlib shouldn’t allocate behind your back, except for thread spawn where it does: https://github.com/ziglang/zig/blob/5cd7fef17faa2a40c8da23f0...
Generally speaking, it’s as mentioned just a convention. A zig library might not allow its users to pass allocators for example.
In C++, stl containers can take an allocator as a template parameter. Recent C++ versions also provide several polymorphic allocators in the stdlib. You can also override the global allocator or a specific class’ allocator (override placement new).
You also linked specifically to the POSIX threads implementation of thread spawning, which is by definition supposed to play nicely with the libc posix threads API, which expects you to use the libc allocator in combination with POSIX threads API, so that's what it does.
You might as well accuse the mmap() function in the zig standard library of allocating behind your back.
1. https://ziglang.org/learn/why_zig_rust_d_cpp/#no-hidden-allo...
shouldn't X, exceptor for Y where it does [X]
It makes perfect sense that GP was saying "thread spawn allocates behind your back".
Does it really matter when people were already writing code with strdup when the zig and rust creators were in middle school ? It was already there in BSD 4.3 (1986) apparently.
Everything old is new again...