Programming on Unix and automatic memory management
utcc.utoronto.ca
utcc.utoronto.ca
It's possible to program in C without manual memory management.
I was not suggesting that any of both is a good idea - but they are tools 'for programs where the amount of items you must store is only known at run time.' (Assuming that not having to free is considered "automatic memory management").
But I agree, in practice, the change to VLAs feels more deprecation-like, because they got demoted to optional because everyone more or less recognised that they're a bad idea, I don't imagine GCC will remove it any time soon but I wouldn't be surprised if it got options to disable them and if those options eventually became enabled by default.
Of course you are right that it's not the same as using e.g. a Python List.
Furthermore, neither does any memory management, the memory is retained till the end of the program. "Simple memory acquisition" perhaps, "memory management" not, except if we accept it as a degenerate case, where things aren't even freed except when the program ends.
And the difference between 'char buf[size]' and 'char *buf = alloca(size)' isn't significant enough to put the two in separate paradigms IMO, just slightly different ways of writing the same thing.
I see, but you still have to ask nicely for it explicitly.
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?
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).
[0] For more details, see e.g. https://nullprogram.com/blog/2019/10/27/
Usually it's not necessary to load everything into memory. It's usually more efficient to process data similar to map-reduce, and just use stdio and stdout
"Static memory" is just a named reference to a memory location in the program data section.
ldedit
I do not know if Linux or the BSDs have the same, or if it is even needed on those systems.
Not sure what this post is about. Automatic memory management is a property of the language, not the operating system. UNIX has had languages with AMM since forever, and those existed way before UNIX too.
UNIX has had languages with AMM since forever
and b) the fact that those languages are core parts of UNIX. It isn't just a kernel, it's also tools like bash and awk.
I think it's a decent rebuttal to people saying, e.g., "Java isn't UNIX-y because it needs a garbage collector". Which I don't think I've heard recently, but I have heard in the past.
In contrast, (IIRC) on the Amiga the OS didn't have per-process resource tracking, e.g. memory leaks would persist after a program was closed or had crashed.
Yeah, you still can do manual memory management, but thats by accident because it's a compiled language. You don't get manual memory management by accident when designing an interperted language because you would have to interpret it explicitly.
This article just reads like it's from 2006.
Modern C++ is still pretty much a niche in the C++ universe, and what makes it so quixotic to push security programming practices to many C++ developers.
Orthodox C++ even exists as a counter movement.
I remember correctly, in the early days, it was frowned upon to program in c if the same could be done using shell scripts and awk, sed and friends. But these are the days of multi-gig applications a no one cares about using UN*X as originally designed.