This is the mail archive of the
mailing list for the GCC project.
Re: using C++ STL containers in GCC/gfortran source code
- From: Janus Weil <janus at gcc dot gnu dot org>
- To: "N.M. Maclaren" <nmm1 at cam dot ac dot uk>
- Cc: gcc mailing list <gcc at gcc dot gnu dot org>, gfortran <fortran at gcc dot gnu dot org>, Jakub Jelinek <jakub at redhat dot com>
- Date: Fri, 16 Dec 2016 18:33:31 +0100
- Subject: Re: using C++ STL containers in GCC/gfortran source code
- Authentication-results: sourceware.org; auth=none
- References: <CAKwh3qgUN=mTFPg6Ew6Yk9RXgS3CttE7O3cGMQRcLKNqUOjBng@mail.gmail.com> <Prayer.email@example.com>
2016-12-16 18:16 GMT+01:00 N.M. Maclaren <firstname.lastname@example.org>:
> On Dec 16 2016, Janus Weil wrote:
>> What I'd like to know is: In the current state of things in GCC, is it
>> possible/reasonable to use any of the STL containers (like
>> std::vector, std::string, whatever) in GCC and its front ends (in
>> particular gfortran)?
>> That question has two parts:
>> 1) Is it technically possible at all? Are there drawbacks/pitfalls?
>> (In particular Jakub mentioned possible memory management issues, i.e.
>> xmalloc vs malloc etc.)
> I can say something about this, which is not gcc-specific. The executive
> summary is that there shouldn't be any problem if you KISS, but heaven
> help you if you don't.
thanks for this lengthy comment, but that's really not the kind of
discussion I wanna get into here. (And I don't actually agree to all
of your points, but that doesn't matter.)
What I want to discuss is deeply GCC-specific, the central point
being: If I use some STL container in one of the front ends (like
gfortran), does that mess with GCC's idea of memory management? To
quote Jakub from PR 78822, commenting on my proposal to use
std::string in gfortran:
"You would need to make sure it uses a xmalloc based allocator first
or at least calls xmalloc_failed upon allocation failure, otherwise it
will be a serious regression."
I'm really not an expert on GCC's memory management principles and how
it uses xmalloc over malloc. I'd love to hear further comments on the
above sentence (e.g. whether that is really necessary, and if yes, how
to accomplish it). And in particular: How do the current uses of
std::string in GCC deal with this problem? (Do they?)