3 ms·
> I liked the article! But I don't think that Rust has static gc because it would imply that C has it too. I Could you clarify how C would count? From my unde
by epage 8y ago
> I liked the article! But I don't think that Rust has static gc because it would imply that C has it too. I
Could you clarify how C would count?
From my understanding of the article's premise, a key part is whether the memory management is automatic or not. In C, everything on the heap is manual, you have to explicitly free and ensure it lives long enough for all owners and borrowers
C++ adds RAII. Going by the article, you might be able to refer to this as gradual automatic memory management except it only helps with the owners and not borrowers.
Rust has owner and borrow tracking, it just verifies it all at compile time and not runtime like traditional GCs (unless you opt-in to Rc). This puts it in a weird middle ground where I can see it being referred to as either automatic or manual, depending on how you look at it.
- arghwhat 8y ago> From my understanding of the article's premise, a key part is whether the memory management is automatic or not. In C, everything on the heap is manual, you have to explicitly free and ensure it lives long enough for all owners and borrowers But everything on the stack is automatic, so by this definition any type of automatic memory management being a "GC", then C has a GC (stack), paired with an unsafe mode (heap).
- jashmatthews 8y ago> then C has a GC (stack) IIUC the C11 standards etc actually just say "automatic storage" and stacks are never specifically mentioned.
- arghwhat 8y agoAh, yes, I forgot the term. C goes to great lengths to avoid defining/touching machine details, which is quite ironic considering how it has gained reputation in this day and age as a very low-level language.
- bjourne 8y agoBecause C has automatic variables. https://en.wikipedia.org/wiki/Automatic_variable https://en.wikipedia.org/wiki/Automatic_variable For the argument "that's a different kind of memory" see this thread from last week: https://news.ycombinator.com/item?id=18124431 https://news.ycombinator.com/item?id=18124431 It is entirely possible to write complex C programs using nothing but automatic variables.
- zbentley 8y agoFrom the wiki: > In C, using the storage class register is a hint to the compiler to cache the variable in a processor register. Other than not allowing the referencing operator (&) to be used on the variable or any of its subcomponents, the compiler is free to ignore the hint. Doesn't sound like a garbage collector to me, by any stretch of the imagination.
- berti 8y agoThe register hint is a bit of a semi-unrelated sidetrack, which you would only ever use in a really hot location when proven necessary by profiling + inspection of the generated code, and the compiler is more often than not smarter than you anyway so it's rarely necessary. It's not relevant to GPs point about regular locals being stored on the stack. See https://en.wikipedia.org/wiki/C_syntax#Storage_class_specifiers https://en.wikipedia.org/wiki/C_syntax#Storage_class_specifi... for a better overview.
- kaoD 8y agoThis is not garbage collection because these are stack (or statically) allocated. The "garbage" in "GC" are heap allocations. If we ignore the heap in C it doesn't make it a GC'd language because the concept of GC isn't even defined with no heap. > It is entirely possible to write complex C programs using nothing but automatic variables For a very narrow subset of "complex". As soon as dynamically-sized type is introduced you need the heap. It's also surprisingly inefficient: suddenly all your buffers (including strings) must be as long as the largest buffer you could imagine you'd need. Which also introduces artificial limits.