3 ms·
>How is it not just two slightly different syntaxes for the same thing? Well, anything that ends up allocating some memory for you and giving you back handler
by coldtea 4y ago
>How is it not just two slightly different syntaxes for the same thing?
Well, anything that ends up allocating some memory for you and giving you back handler would be also "slightly different syntax for the same thing".
I'd say that the first case abstracts away the allocation though, while the second makes it explicit. It's just too small an example to be that big of a difference.
Another thing that comes to mind, is that you can just write:
char buf[4] = "foo";
to initialize the string, whereas with alloca you'd need something like:
char* buf = alloca(4);
strcpy(buf, "foo");
Isn't the latter quite more manual?
- mort96 4y agoSo you think two different syntaxes for allocating N bytes of automatically managed (i.e stack) memory are in fundamentally different classes of memory management because one is slightly more explicit than the other (because a pointer is returned or something I guess?). I don't agree, but at this point, it's semantics. In the literature though, you may find that "manual" memory management usually refers to memory management where the programmer has to call a 'free'-style function manually, while automatic memory management usually refers to anything where the programmer doesn't have to call 'free' (be it thanks to lifetimes or GC or automatic refcounting or whatever).