chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] foreign: Why is passing structs as arguments and ret


From: Alaric Snell-Pym
Subject: Re: [Chicken-users] foreign: Why is passing structs as arguments and return-types not supported?
Date: Wed, 29 Feb 2012 14:26:23 +0000
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 02/29/2012 01:29 PM, Thomas Chust wrote:

> Last but not least, passing structures as pointers makes memory
> management for them explicit and that is a good thing in this case
> because there is simply no way the FFI could automatically figure out
> how the optimal memory management strategy for structures passed by
> value should look like. For example, whether such a structure can be
> allocated as an atomic block of memory or not is impossible to answer
> without knowing what the functions producing and consuming instances of
> the structure actually do.

I slightly disagree here. A structure passed or returned by value is
just shoved on the stack, maybe in registers if it's a small structure.
There's no extra memory management required; merely some extra copying
to copy from the Chicken-side foreign-type pointer into the appropriate
bit of stack or registers, or back again for returned values.

But, indeed, it's easy to do that in C as your distim demonstration
shows; return values are only slightly harder as you'll need to allocate
a struct and copy the result in, then return that pointer.

ABS

- --
Alaric Snell-Pym
http://www.snell-pym.org.uk/alaric/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk9ONY8ACgkQRgz/WHNxCGpVFQCdFmrrkp6RhMkQQNIaRtElcQUw
At8An3tuScsj6vKNCi/CQDVVTeRR1ZHE
=foQX
-----END PGP SIGNATURE-----



reply via email to

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