[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C++, exception, and memory handling

From: Valentin Tolmer
Subject: C++, exception, and memory handling
Date: Sun, 3 Mar 2019 18:09:18 +0100


I'm currently in the process of adapting the GLR C++ parser to handle
variant types, and in the process I'm modernizing the code, and making it
more typical C++.

There is a dichotomy in our memory handling:
- On the one hand, we work hard to propagate and cleanup OOM errors.
- On the other hand, we use a stack based on std::vector in lalr.cc, and we
allow users to disable exceptions, which would lead to an uncatcheable
std::bad_alloc in case of memory exhaustion.

So, do we want to keep the policy of propagating as nicely as possible OOM
errors, leading us to only using hand-made data structures calling malloc
(or no-throw new)? Or do we just write C++ code that will correctly behave
in case of an exception, and then we can modernize the code to use STL
containers? One thing to point, that I saw on several SO answers, is that
modern OS tend to over-commit on memory, with malloc always returning a
non-null pointer, up until you try to access the memory where it fails with
SIGSEGV. So trying to handle OOM seems hard (apart from the hard-coded
10000 elements limit in the code).

I would vote for the second option, of course, but I don't know if some
people rely on the first behavior.

Valentin Tolmer

reply via email to

[Prev in Thread] Current Thread [Next in Thread]