chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] call Chicken Scheme from C and pass a bytevector


From: Dan Leslie
Subject: Re: [Chicken-users] call Chicken Scheme from C and pass a bytevector
Date: Thu, 27 Jun 2013 10:25:53 -0700
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2

There's a section on accessing external objects that covers this sort of thing:
http://wiki.call-cc.org/man/4/Accessing%20external%20objects#returning-large-objects-or-chunks-of-memory-to-scheme

It's possible to allocate C structures under the control of the Chicken GC:
http://wiki.call-cc.org/allocating-c-structures-under-control-of-the-chicken-gc

However, you can also leave control up to the user rather than the GC and they can use free:
http://api.call-cc.org/doc/lolevel/free

Personally, I like to allocate blobs and srfi-4 vectors in scheme and pass them as parameters to C functions to be mutated.

-Dan

On 6/27/2013 10:07 AM, Claude Marinier wrote:
Hi,

A function in pcap-interface.c calls Chicken Scheme. It builds a vector containing a bunch of things, e.g. C_fix(ethtype), and the source and destination addresses as vectors. The scheme code converts the address vectors to u8vector (u16vector for IPv6). This is a lot of work: just under 20% of CPU time is spent in vector->u8vector.

If I could create a blob in C and pass it to scheme, the scheme code could use blob->u8vector/shared and blob->u16vector/shared which would achieve the same result with much less work.

What is the recommended way to pass a blob to scheme from C?

Is there a way to create a u8vector or u16vector directly in C?

Thank you.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]