* attempt to make a transparent binding
@ 2004-12-06 6:15 Oleg A. Paraschenko
2004-12-06 17:26 ` Stephen Compall
0 siblings, 1 reply; 3+ messages in thread
From: Oleg A. Paraschenko @ 2004-12-06 6:15 UTC (permalink / raw)
Hello,
I'm making a binding to a C program. One of the memory structures in
the program is a list which can contain sublists and strings. I'd like
to present this structure as the Scheme list in Guile, so the usual list
functions like 'car', 'cdr', 'for-each' etc would work.
A trivial approach is to write a function (let name it "memory->list")
which creates a real Scheme list from the data. But I wonder if it is
possible to complicate things.
First, the data in memory are big enough, and full instantiation of
lists wastes resources, especially because I use only small part of the
data. Instead, I'd like to have lazy instantiation. Let "memory->list"
returns a special type of pair in which car and cdr are instantiated on
demand. Is it possible?
The second. Having Scheme data, I'd like to get the origin of this data
in the C program. Currently I think about mapping from SCMs to C
structures in C-Guile glue, but I'm afraid this is bad for garbage
collection.
I'd be thankful for your comments and suggestions.
Regards, Oleg
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: attempt to make a transparent binding
2004-12-06 6:15 attempt to make a transparent binding Oleg A. Paraschenko
@ 2004-12-06 17:26 ` Stephen Compall
2004-12-08 7:21 ` Oleg A. Paraschenko
0 siblings, 1 reply; 3+ messages in thread
From: Stephen Compall @ 2004-12-06 17:26 UTC (permalink / raw)
Cc: guile-user
"Oleg A. Paraschenko" <olpa@datahansa.com> writes:
> First, the data in memory are big enough, and full instantiation
> of lists wastes resources, especially because I use only small part
> of the data. Instead, I'd like to have lazy instantiation. Let
> "memory->list" returns a special type of pair in which car and cdr
> are instantiated on demand. Is it possible?
This is what Scheme's "promises" are for. However, I do not know
Guile's promise support, as I've never looked at that part of the
source, and have never needed them myself.
> The second. Having Scheme data, I'd like to get the origin of this
> data in the C program. Currently I think about mapping from SCMs to
> C structures in C-Guile glue, but I'm afraid this is bad for garbage
> collection.
I can't think of any other way. If you were using smobs, the natural
thing would be to use a slot for a pointer back to the C struct.
However, you aren't.
As for garbage collection, you could drop the SCMs in a gc protected
guardian, and remove objects you can pull from the guardian every time
you look in your table.
The other solution, if you are really worried about resource usage, is
to eliminate duplication by changing the internal representation of
your program to use SCMs. Then you could scm_permanent_object a
variable containing a list of current SCMs that may only be live in C.
Further transformation could open up the possibility of writing new
parts of the program in Scheme, or rewriting buggy sections :)
--
Stephen Compall or s11 or sirian
It's not reality or how you perceive things that's important -- it's
what you're taking for it...
halcon interception Serbian Peking world domination espionage SSL
credit card SHA explosion mania infowar embassy ANDVT ASO
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: attempt to make a transparent binding
2004-12-06 17:26 ` Stephen Compall
@ 2004-12-08 7:21 ` Oleg A. Paraschenko
0 siblings, 0 replies; 3+ messages in thread
From: Oleg A. Paraschenko @ 2004-12-08 7:21 UTC (permalink / raw)
Cc: guile-user
Hello Stephen,
thank you for comments.
On 06 Dec 2004 11:26:30 -0600
Stephen Compall <s11@member.fsf.org> wrote:
> "Oleg A. Paraschenko" <olpa@datahansa.com> writes:
>
> > First, the data in memory are big enough, and full instantiation
> > of lists wastes resources, especially because I use only small part
> > of the data. Instead, I'd like to have lazy instantiation. Let
> > "memory->list" returns a special type of pair in which car and cdr
> > are instantiated on demand. Is it possible?
>
> This is what Scheme's "promises" are for. However, I do not know
> Guile's promise support, as I've never looked at that part of the
> source, and have never needed them myself.
Nice suggestion. I've completely forgotten about Scheme promises.
They can't help me because I can't insert "force"s to the existing code,
but anyway now I have several ideas.
>
> > The second. Having Scheme data, I'd like to get the origin of this
> > data in the C program. Currently I think about mapping from SCMs to
> > C structures in C-Guile glue, but I'm afraid this is bad for garbage
> > collection.
>
> I can't think of any other way. If you were using smobs, the natural
> thing would be to use a slot for a pointer back to the C struct.
> However, you aren't.
>
> As for garbage collection, you could drop the SCMs in a gc protected
> guardian, and remove objects you can pull from the guardian every time
> you look in your table.
>
> The other solution, if you are really worried about resource usage, is
> to eliminate duplication by changing the internal representation of
> your program to use SCMs. Then you could scm_permanent_object a
> variable containing a list of current SCMs that may only be live in C.
> Further transformation could open up the possibility of writing new
> parts of the program in Scheme, or rewriting buggy sections :)
Thank you, I'll try to understand it.
>
> --
> Stephen Compall or s11 or sirian
>
> It's not reality or how you perceive things that's important -- it's
> what you're taking for it...
>
--
Oleg
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-12-08 7:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-12-06 6:15 attempt to make a transparent binding Oleg A. Paraschenko
2004-12-06 17:26 ` Stephen Compall
2004-12-08 7:21 ` Oleg A. Paraschenko
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).