|
|
|
|
|
by alchemio
820 days ago
|
|
Just a correction: most std C functions don’t allocate. strdup does but it was only recently adopted into the standard, it was previously an extension. 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.