News for hackers. Stuff that matters.
Re:When a disk cache performs better than an in-memory cache by bluejekyll on Sunday October 02, 2016 @08:18PM (#12624939)
> [the GC] ...it's keeping you from the misery of manual memory management and that you're better to consider it an ally than a foe

I used to think this way, then I tried Rust. After C and C++, I never thought I'd want to give up the GC, but to avoid the issues that this article talks about, I wanted to go back to a systems language.

Now I want to use Rust for everything.

Re:When a disk cache performs better than an in-memory cache by saynsedit on Monday October 03, 2016 @01:38AM (#12625650)
RAII in Rust comes from C++. If you're using new/delete in C++, you're doing it wrong.
Re:When a disk cache performs better than an in-memory cache by catnaroek on Monday October 03, 2016 @03:28AM (#12625886)
Sure, but RAII alone doesn't make resource management safe. It's the combination of RAII and lifetime checking that achieves it.
Re:When a disk cache performs better than an in-memory cache by rcfox on Monday October 03, 2016 @06:48AM (#12626396)
Not everything can live on the stack.

If you're not using new/delete in C++, you're probably not doing something very complicated. (And hey, that's not necessarily a bad thing!)

Re:When a disk cache performs better than an in-memory cache by netheril96 on Monday October 03, 2016 @07:01AM (#12626452)
The resource manager (like std::vector or std::unique_ptr) can certainly live on the stack when the data it manages resides on the heap.
Re:When a disk cache performs better than an in-memory cache by saynsedit on Monday October 03, 2016 @11:49AM (#12628402)
RAII can wrap heap-allocated data. Also bss-allocated objects are common.
Re:When a disk cache performs better than an in-memory cache by Kenji on Monday October 03, 2016 @07:24AM (#12626554)
Uhh... RAII is perfectly compatible with new/delete. You just have to put all new calls in the constructor and all delete calls in the destructor.
Re:When a disk cache performs better than an in-memory cache by saynsedit on Monday October 03, 2016 @11:54AM (#12628468)
Yes Kenji... You put new/delete in constructor/destructor so that you don't have to call new/delete manually.
Re:When a disk cache performs better than an in-memory cache by Kenji on Monday October 03, 2016 @01:08PM (#12629243)
Oh, I misunderstood you. I thought you would write code without a single new or delete at all. So, everything is either living on the stack or using built-in allocations like vector and the like.
Re:When a disk cache performs better than an in-memory cache by slededit on Monday October 03, 2016 @01:48PM (#12629633)
In modern C++ you do avoid it completely. Using things like std::make_unique<> and std::make_shared<> to allocate an object and stuff it into a smart pointer immediately.
Re:When a disk cache performs better than an in-memory cache by Kenji on Monday October 03, 2016 @02:26PM (#12629992)
Thanks. I always wanted to learn modern C++, but there was no such lecture at uni and in my spare time I was only able to fill the gaps partially, learning about the obvious things like the auto keyword and move constructors and the like.
Re:When a disk cache performs better than an in-memory cache by slededit on Monday October 03, 2016 @02:50PM (#12630218)
Move constructors get a lot of press because they are new (and necessary for the underlying machinery of unique_ptr to work). But most people will never need to use it or know about it directly.

There are really two classes of C++ features, the basic use part which is fairly straightforward and nice to use. This is the API provided by the STL. Followed by the infrastructure stuff like templates, move semantics, SFINAE and other messy and non-obvious things. This latter part is much more complicated and still a mine field - but necessary for the STL to do what it does.

If you want to learn C++ get proficient in using the STL. The rest should only be learned once that is second nature.

Re:When a disk cache performs better than an in-memory cache by zamalek on Monday October 03, 2016 @06:01AM (#12626264)
> avoid the issues that this article talks about

Slight caveat.

> Step 3: Pooling large byte arrays used in serialisation/deserialisation

If you are using a explicit memory language, buffer pooling is still quite important - especially if you are doing any IO. You can avoid this to a certain degree by using fast malloc implementations.

Re:When a disk cache performs better than an in-memory cache by catnaroek on Monday October 03, 2016 @01:49PM (#12629641)
Why not both? I want both GC for recursive data structures (lists, trees, graphs, etc.) and Rust-style resource management when deterministic reclamation matters (files, GUI objects, etc.).
Re:When a disk cache performs better than an in-memory cache by bluejekyll on Monday October 03, 2016 @03:14PM (#12630416)
This is something that is in discussion, though I don't know the status of any of the discussions:

https://internals.rust-lang.org/t/on-native-allocations-poin...

https://github.com/rust-lang/rfcs/blob/bdbe73d1be948dd925c6b...

Re:When a disk cache performs better than an in-memory cache by catnaroek on Monday October 03, 2016 @05:13PM (#12631376)
I should've been clearer: For low-level programming, Rust is already fine as it is. What I want is a high-level language that offers some of the benefits of Rust (safe deterministic non-memory resource management), without the unnecessarily low-level features (sized types and overemphasis on unique ownership). Due to its C++ heritage, Rust has a tendency to conflate ownership (a high-level concern) with indirection (a low-level one), which is fine for the niche it targets, but too inflexible for general-purpose programming, IMO.
Re:When a disk cache performs better than an in-memory cache by fridsun on Monday October 03, 2016 @06:05PM (#12631756)
OCaml or Haskell.
Re:When a disk cache performs better than an in-memory cache by catnaroek on Monday October 03, 2016 @06:34PM (#12631932)
Neither OCaml nor Haskell has substructural types. There's no way to tell their type systems “you can't use a file after it's been closed”. In fact, what I want can be summarized as “ML plus substructural types”! (But preferably with Standard ML as the base point, since OCaml has way too many warts for my taste.)