[gambit-list] How to pass a Scheme string to a const char*?

Mikael mikael.rcv at gmail.com
Wed Dec 21 12:17:43 EST 2011

2011/12/19 Sascha Ziemann <ceving at gmail.com>

> 2011/12/14 Marc Feeley <feeley at iro.umontreal.ca>:
> >
> > When a Scheme string is "converted" to a C string by the C-interface, it
> is a newly allocated object on the C heap.  In other words, the object that
> C is receiving is unrelated to the Scheme object managed by the Gambit
> garbage-collector.  The C string will *not* be moved around, but it does
> have a reference count which allows more control over the reclaiming of
> that string from the C side.
> So there are two strings: one on the Scheme side and one on the C
> side. The one on the Scheme side probably does not have any Scheme
> references any more but has one reference coming from the C side.

> Isn't this a bit much overhead to keep the string on the Scheme side,
> only to have a reference to the copy of the string on the C side?

You can access the Scheme string's content "raw" as well from C. The point
with the conveniency wrapper into char* etc. in C, is to give you a
latin1/utf8/etc. encoded character sequence rather than the internal
32bit/etc. unicode form.

> And another question: if there are also references on the Scheme side
> to the string which get used to modify the string: will the C side
> know about the modification?

No afaik

> Example:
> (let ((ident "A"))
>  (openlog ident ...)
>  (syslog "a")
>  (set! ident "B")
>  (syslog "b"))
> Will the output be
> A: a
> B: b
> or
> A: a
> A: b
> ?
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20111221/111b2584/attachment.htm>

More information about the Gambit-list mailing list