7 ms·
I'm absolutely in love with C++'s RAII scheme but it seems almost no languages use it and, instead, go with a complex garbage collecting scheme that requires pa
by BinaryIdiot 12y ago
I'm absolutely in love with C++'s RAII scheme but it seems almost no languages use it and, instead, go with a complex garbage collecting scheme that requires pausing.
I want to like GO but a language that targets native development but still uses garbage collection just seems like an odd pairing to me. Maybe it's just me especially since I rarely get an opportunity to do native development.
- masklinn 12y ago> I'm absolutely in love with C++'s RAII scheme but it seems almost no languages use it RAII is but one resource-management strategy, and one intrinsically linked to C++'s memory model. But if that's what you're looking for, Rust uses the same: http://doc.rust-lang.org/std/ops/trait.Drop.html http://doc.rust-lang.org/std/ops/trait.Drop.html And in the absence of cycles, refcounted implementations have similar properties (although of course that assumption will break with alternate non-refcounted implementations if refcounting is not part of the language semantics). > I want to like GO but a language that targets native development but still uses garbage collection just seems like an odd pairing to me. Not that rare. OCaml is native and GC'd, so is D, or most lisps with native compilers. Hell, Boehm's GC exists.
- Cyther606 12y agoWith Nimrod, you can manage your own memory, or use the GC (Boehm iirc) http://nimrod-lang.org/manual.html#reference-and-pointer-types http://nimrod-lang.org/manual.html#reference-and-pointer-typ...
- dom96 12y agoIndeed, and Nimrod's own GC is actually soft real-time (http://build.nimrod-lang.org/docs/gc.html http://build.nimrod-lang.org/docs/gc.html) with hard real-time already in the works.
- dilap 12y agoObjC, with automatic-reference-counting (and now Swift, I assume, though I haven't looked into it) is close to garbage collection, but has deterministic destruction. The price you pay is you have to manually avoid cycles by annotating some references as weak. It's a very nice scheme, actually.
- masklinn 12y ago> and now Swift, I assume, though I haven't looked into it Correct, Swift is built on top of the obj-c runtime (more or less) and also uses ARC.
- pcwalton 12y agoThread-safe reference counting usually has lower throughput than tracing garbage collection. If it's throughput you're after, you're not going to get it with atomic reference counting.
- masklinn 12y agoOTOH refcounting has a more stable (and usually lower on average) memory usage, and no pauses (if cycles are ignored)
- Tuna-Fish 12y ago> and no pauses (if cycles are ignored) Actually, even without cycles the destruction time is in general unbounded. Just think what happens when you allocate a very long linked list one element at a time and then drop the head. With a bit of ill luck or intention, you can make each element be allocated from a different page with enough different pages so that they fall out of the TLB. In that situation, even without having pages written out to disk, you can expect each element to take ~ a thousand cycles to free. On a million element list, that's ~500ms for freeing the head.
- TheLoneWolfling 12y agoYou can do reference counting asynchronously, though.
- Dewie 12y ago> I want to like GO but a language that targets native development but still uses garbage collection just seems like an odd pairing to me. Why? I don't see what is weird about that combination. Garbage collection is usually something that is used in high-level languages, and high-level languages might as well be natively compiled as opposed to interpreted, running on a vm, etc. If anything, C/++ seems like the odd pair out with their more manual memory management among native languages.