From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Neil Jerram" Newsgroups: gmane.lisp.guile.devel Subject: Re: Internal visibility Date: Mon, 9 Jun 2008 19:10:23 +0100 Message-ID: <49dd78620806091110v7a667787mef392fbf4446139d@mail.gmail.com> References: <87k5i5d6ei.fsf@ossau.uklinux.net> <8763tomqn7.fsf@ossau.uklinux.net> <87lk2jhp0h.fsf@gnu.org> <87skwrce8y.fsf@ossau.uklinux.net> <87iqxledzz.fsf@gnu.org> <87lk2futg0.fsf@ossau.uklinux.net> <87fxslr1jr.fsf_-_@gnu.org> <878wxv5t7q.fsf@gnu.org> <87mym6dv6t.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1213035058 23502 80.91.229.12 (9 Jun 2008 18:10:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 9 Jun 2008 18:10:58 +0000 (UTC) Cc: guile-devel@gnu.org To: hanwen@xs4all.nl Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Jun 09 20:11:40 2008 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1K5lq5-0005ky-2Y for guile-devel@m.gmane.org; Mon, 09 Jun 2008 20:11:29 +0200 Original-Received: from localhost ([127.0.0.1]:53318 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K5lpH-0008Qu-No for guile-devel@m.gmane.org; Mon, 09 Jun 2008 14:10:39 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K5lpB-0008Op-E5 for guile-devel@gnu.org; Mon, 09 Jun 2008 14:10:33 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K5lpA-0008NM-FQ for guile-devel@gnu.org; Mon, 09 Jun 2008 14:10:32 -0400 Original-Received: from [199.232.76.173] (port=59991 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K5lpA-0008NC-9M for guile-devel@gnu.org; Mon, 09 Jun 2008 14:10:32 -0400 Original-Received: from yw-out-1718.google.com ([74.125.46.154]:17616) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K5lpA-0003oQ-9X for guile-devel@gnu.org; Mon, 09 Jun 2008 14:10:32 -0400 Original-Received: by yw-out-1718.google.com with SMTP id 9so1249255ywk.66 for ; Mon, 09 Jun 2008 11:10:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=oFK6ULPhZx7vpm3WxUcsN88drAkIVZgK97HefOBPjb0=; b=o+VawwEG1/VTWBFi2PTiwhFGRtL6GoIC3Ej6KWFZxRx/OU/QBDItMyx6lbwhhatwMF HvqTzjcTpx4kXLvcc88NYE8NmGMc0B1E7JATUrlnOavnZ+nOpHScaKj+d25xvn3fSr7t 5nIvPyESOBlOloDPkTf9AQRKNwddEDwfcx8Zc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=fyDMOYc5xHwAroyZa65a1M9cZJHE17nMZWjeMbabNyFT1axRXjsS4cL6iqtGjc6sFC BWWkplEIoHypMcNmziX82yDPxbu13GC/Ln6XJLbaEMZNcvzWbXmRH0BHxJawIMglLLYw wnXakMOk+aSuedAW7tUuPHKVbKran12xTcGF8= Original-Received: by 10.114.36.4 with SMTP id j4mr3729529waj.156.1213035023780; Mon, 09 Jun 2008 11:10:23 -0700 (PDT) Original-Received: by 10.114.197.8 with HTTP; Mon, 9 Jun 2008 11:10:23 -0700 (PDT) In-Reply-To: Content-Disposition: inline X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:7307 Archived-At: 2008/6/1 Han-Wen Nienhuys : > const char* ptr = scm_i_string_chars(scmval); > string x(ptr); > > is the most straightforward and efficient way to create a string. > Using the API incurs an additional malloc, memcpy and free. Does "string x(ptr)" incur a malloc and memcpy? I assume it must do, or else the code above would be unsafe (sharing memory between the C++ and SCM strings). So, assuming it does, why do you think this is Guile's problem, and not C++'s? To put it another way: can you use another form of C++ string construction that does not do a malloc/memcpy itself, but takes ownership of the char * that is passed to it? Then you could use this together with scm_to_locale_string(), and you'd still only have one malloc/memcpy overall. Guile's string API is aiming not to be 8-bit-assuming, and I would guess from the code above that the C++ string class is 8-bit-assuming. Therefore, in the sequence SCM -> char * -> string it makes sense to have the malloc/memcpy between SCM and char *, not between char * and string. More generally, as regards cases where people are currently using scm_i_string_chars(), I can imagine that there are good reasons why - e.g. searching for a particular character or substring. But I think we should be aiming to encapsulate those uses in new APIs that will still work when Guile has non-8-bit strings. Regards, Neil