From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26592 invoked by alias); 18 Oct 2009 01:53:02 -0000 Received: (qmail 26582 invoked by uid 22791); 18 Oct 2009 01:53:02 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mail-px0-f175.google.com (HELO mail-px0-f175.google.com) (209.85.216.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 18 Oct 2009 01:52:58 +0000 Received: by pxi5 with SMTP id 5so1261460pxi.12 for ; Sat, 17 Oct 2009 18:52:57 -0700 (PDT) MIME-Version: 1.0 Received: by 10.142.247.5 with SMTP id u5mr192527wfh.333.1255830777106; Sat, 17 Oct 2009 18:52:57 -0700 (PDT) In-Reply-To: <20091015191656.GF5272@adacore.com> References: <4AD761AD.40307@vmware.com> <20091015191656.GF5272@adacore.com> From: Hui Zhu Date: Sun, 18 Oct 2009 01:53:00 -0000 Message-ID: Subject: Re: [RFA] record.c - save some memory in record log. To: Joel Brobecker Cc: Michael Snyder , "gdb-patches@sourceware.org" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-10/txt/msg00403.txt.bz2 > > 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: > > =A0 struct blah > =A0 { > =A0 =A0 ... > > =A0 =A0 int buffer_len; > =A0 =A0 gdb_byte buf[0]; > =A0 }; > > 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. =A0But 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