[mercury-users] passing arrays of floats to C

Julien Fischer juliensf at csse.unimelb.edu.au
Mon Jun 28 14:00:14 AEST 2010


Hi,

On Thu, 24 Jun 2010, James Cussens wrote:

> Perhaps, the following got lost due to mailing list problems, so here it is 
> again ....
>
> Thanks for Julien for his tip about MR_word_to_float.

You're welcome.

> I've got a related question. I'm passing a (Mercury) list of floats to a
> C function which then populates a C array of floats from its elements.
> It would be just as easy to have the Mercury list of floats replaced
> with a Mercury array of floats.
>
> In this case is there a direct way of creating the corresponding C
> array, or do we have to plod through the elements?

Presumably, you mean to use something like memcpy() on the C
representation of the Mercury array to populate the C array?

It wouldn't be possible to do that portably since (1) the elements of the
Mercury array may be boxed and (2) even in the unboxed case you would
need to ensure that the elements of each array had the same size.

Unless, plodding through the elements when going from Mercury -> C is
proving a bottleneck then I wouldn't worry about it.  If it is, then
rather than using the array/1 type I would consider using a data
structure that allows Mercury and C to share the underlying array
directly.

Julien.
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list