This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA] record.c - save some memory in record log.
- From: Hui Zhu <teawater at gmail dot com>
- To: Joel Brobecker <brobecker at adacore dot com>
- Cc: Michael Snyder <msnyder at vmware dot com>, "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Sun, 18 Oct 2009 09:52:37 +0800
- Subject: Re: [RFA] record.c - save some memory in record log.
- References: <4AD761AD.40307@vmware.com> <20091015191656.GF5272@adacore.com>
>
> One way that we have used in the past that might be helpful here
> is to define the buffer at the end of the structure and without
> the pointer indirection:
>
> ? struct blah
> ? {
> ? ? ...
>
> ? ? int buffer_len;
> ? ? gdb_byte buf[0];
> ? };
>
> The allocation of the structure become a little trickier. And access
> to the buffer is a little more dangerous, which is why I don't like
> this approach much. ?But it does save memory, and you can prevent
> buffer overrun by forcing access to this data through accessor
> routines...
>
Hi Joel,
But I think:
+ union
+ {
+ gdb_byte *ptr;
+ gdb_byte buf[2 * sizeof (gdb_byte *)];
Make the size of buf more clear.
Thanks,
Hui