unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: "Neil Jerram" <neiljerram@googlemail.com>
To: hanwen@xs4all.nl
Cc: guile-devel@gnu.org
Subject: Re: Internal visibility
Date: Mon, 9 Jun 2008 19:10:23 +0100	[thread overview]
Message-ID: <49dd78620806091110v7a667787mef392fbf4446139d@mail.gmail.com> (raw)
In-Reply-To: <g1v0ji$3n1$1@ger.gmane.org>

2008/6/1 Han-Wen Nienhuys <hanwen@xs4all.nl>:

>  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




  reply	other threads:[~2008-06-09 18:10 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-07 23:46 [PATCH] Fix continuation problems on IA64 Neil Jerram
2008-05-08 20:09 ` Ludovic Courtès
2008-05-08 21:29   ` Neil Jerram
2008-05-09  8:15     ` Ludovic Courtès
2008-05-09 22:19       ` Neil Jerram
2008-05-11  3:06         ` Ludovic Courtès
2008-05-12 21:02           ` Neil Jerram
2008-05-14  3:45             ` Internal visibility Ludovic Courtès
2008-05-27 21:32               ` Ludovic Courtès
2008-05-31 21:23                 ` Ludovic Courtès
2008-06-01  8:00                   ` Neil Jerram
2008-06-01 11:05                     ` Ludovic Courtès
2008-06-01 20:48                       ` Neil Jerram
2008-06-01 22:02                         ` Ludovic Courtès
2008-06-01 20:24                   ` Han-Wen Nienhuys
2008-06-09 18:10                     ` Neil Jerram [this message]
2008-06-10  1:51                       ` Han-Wen Nienhuys
2008-06-10  7:37                         ` Ludovic Courtès
2008-06-10  8:04                           ` Thien-Thi Nguyen
2008-06-10 12:09                             ` Ludovic Courtès
2008-06-11  7:49                               ` Thien-Thi Nguyen
2008-06-11 12:20                                 ` Ludovic Courtès
2008-06-12 20:45                                   ` Mike Gran
2008-06-23 12:20                                     ` Ludovic Courtès
2008-06-11  4:05                           ` Han-Wen Nienhuys
2008-06-11  7:18                             ` Ludovic Courtès
2008-06-11  7:24                             ` Clinton Ebadi
2008-06-11  7:39                               ` Ludovic Courtès
2008-06-11 16:09                               ` Han-Wen Nienhuys
2008-06-23 12:18                                 ` Ludovic Courtès
2008-06-11  7:37                             ` Neil Jerram
2008-05-12 22:18     ` [PATCH] Fix continuation problems on IA64 Neil Jerram
2008-05-14  2:55       ` Ludovic Courtès

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

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49dd78620806091110v7a667787mef392fbf4446139d@mail.gmail.com \
    --to=neiljerram@googlemail.com \
    --cc=guile-devel@gnu.org \
    --cc=hanwen@xs4all.nl \
    /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).