From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15905 invoked by alias); 25 Oct 2008 16:46:36 -0000 Received: (qmail 15896 invoked by uid 22791); 25 Oct 2008 16:46:35 -0000 X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 25 Oct 2008 16:45:55 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id m9PGj0e3018005; Sat, 25 Oct 2008 12:45:00 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m9PGixmY009886; Sat, 25 Oct 2008 12:45:00 -0400 Received: from opsy.redhat.com (vpn-12-162.rdu.redhat.com [10.11.12.162]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id m9PGixEW007251; Sat, 25 Oct 2008 12:44:59 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id 66D19508074; Sat, 25 Oct 2008 10:44:58 -0600 (MDT) To: Joel Brobecker Cc: Ulrich Weigand , gdb-patches@sourceware.org Subject: Re: [RFC/RFA] add struct parse_context to all command functions References: <200810231949.m9NJnBUn013007@d12av02.megacenter.de.ibm.com> <20081025162453.GJ29998@adacore.com> From: Tom Tromey Reply-To: Tom Tromey X-Attribution: Tom Date: Sat, 25 Oct 2008 16:46:00 -0000 In-Reply-To: <20081025162453.GJ29998@adacore.com> (Joel Brobecker's message of "Sat\, 25 Oct 2008 09\:24\:53 -0700") Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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: 2008-10/txt/msg00645.txt.bz2 >>>>> "Joel" == Joel Brobecker writes: Joel> I like the idea as well. Just one question: Why did you elect to Joel> pass the structure as a pointer, rather than the structure Joel> itself? To avoid copying. Most users just reference fields from the structure, or pass it through unmodified. So, this is more efficient in the common cases. I would have looked at passing by value if the structure were smaller. As it is, on my machine it is 68 bytes -- that seems kind of big. Joel> I wonder if some of the complexity in terms of who owns the Joel> data, making a copy, etc, could be removed if we passed the Joel> structure itself. In terms of performance, it shouldn't be a Joel> problem, as I expect large structs to be passed by reference Joel> anyway. I think they have to be copied regardless, though, to preserve pass-by-value semantics. In this particular case, ownership is not an issue. These structures are only ever stack-allocated. Passing pointers to const makes it clear that these are not mutable. Stack allocation does make the code a bit uglier, since when we do want to make a copy we have to give the new object a name. That is one advantage of pass-by-value. struct parse_context might be a bit different depending on what you put in it. For example, I was thinking that lexptr should probably not be a global. However, if we put it in parse_context, then the context can't be const. (Maybe we want two different structs though -- one immutable and one to hold state for a given parse.) Tom