3 ms·
> I don't know of any core language features in C++ that allocate dynamic memory any longer. The article mention coroutines. There may also be an allocation wh
by varajelle 6y ago
> I don't know of any core language features in C++ that allocate dynamic memory any longer.
The article mention coroutines.
There may also be an allocation when one throws an exception.
> Everyone calls their project "simple" and everyone has a different meaning for it.
So true. For example, I'd say Brainfuck is simple. And much simpler than Zig. But that does not mean I'd want to use it.
- Kranar 6y agoCoroutines in C++ are a good example, definitely. Rust managed to use the borrow checker to avoid dynamic allocation with coroutines. I wonder how Zig handles this, and I hope it's not through undefined behavior. From reading it over, it looks like Zig does use dynamic memory for coroutines but it requires the memory to be passed in at the point of construction. That has some pros and cons to it and is consistent with Zig's overall approach so I can respect that choice.
- AndyKelley 6y agoNot sure what you mean by dynamic memory. Much like a struct can be stored at any memory address - global, heap, stack - a coroutine ("async function") in zig can be stored at any memory address. Just like `pointer.* = Foo{ .a = 12, .b = 34}`, the pointer decides where the struct memory goes, `pointer.* = async foo();` the pointer decides where the async function's stack frame goes.