From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed 4/5] libstdc++: shrink-to-fit in std::basic_stacktrace::current(skip, max)
Date: Tue, 12 Apr 2022 22:41:27 +0100 [thread overview]
Message-ID: <20220412214128.509227-4-jwakely@redhat.com> (raw)
In-Reply-To: <20220412214128.509227-1-jwakely@redhat.com>
Tested powerpc64-linux, pushed to trunk.
-- >8 --
If a large stacktrace is reduced to a max depth that is less than half
the capacity it will now be reallocated to remove the unused capacity.
libstdc++-v3/ChangeLog:
* include/std/stacktrace (basic_stacktrace::current): Reallocate
a smaller container if the unused capacity is larger than the
used size.
---
libstdc++-v3/include/std/stacktrace | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/libstdc++-v3/include/std/stacktrace b/libstdc++-v3/include/std/stacktrace
index 382d900a822..98ce9231150 100644
--- a/libstdc++-v3/include/std/stacktrace
+++ b/libstdc++-v3/include/std/stacktrace
@@ -289,7 +289,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
if (__err < 0)
__ret._M_clear();
else if (__ret.size() > __max_depth)
- __ret._M_impl._M_resize(__max_depth, __ret._M_alloc);
+ {
+ __ret._M_impl._M_resize(__max_depth, __ret._M_alloc);
+
+ if (__ret._M_impl._M_capacity / 2 >= __max_depth)
+ {
+ // shrink to fit
+ _Impl __tmp = __ret._M_impl._M_clone(__ret._M_alloc);
+ if (__tmp._M_capacity)
+ {
+ __ret._M_clear();
+ __ret._M_impl = __tmp;
+ }
+ }
+ }
}
return __ret;
}
--
2.34.1
next prev parent reply other threads:[~2022-04-12 21:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-12 21:41 [committed 1/5] libstdc++: Reduce memory usage in std::stacktrace::current Jonathan Wakely
2022-04-12 21:41 ` [committed 2/5] libstdc++: Use nothrow new in std::stacktrace Jonathan Wakely
2022-04-12 21:41 ` [committed 3/5] libstdc++: Use allocator to construct std::stacktrace_entry objects Jonathan Wakely
2022-04-12 21:41 ` Jonathan Wakely [this message]
2022-04-12 21:41 ` [committed 5/5] libstdc++: Prefer to use mmap instead of malloc in libbacktrace Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220412214128.509227-4-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).