Passing array of float from Squeak to C

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Passing array of float from Squeak to C

Ang BeePeng
I'm facing problem to pass a float array over to C, to create a plugin.

Previously, I use variableWordSubclass: to create a class to store floats, in an array. It works fine, as floats are stored as words.
Now that I need to have an instance variable, I use variableSubclass: to store floats. It seems like floats are being stored as object in the array this time. The VM crashes when I try to use to same method to access to the float array.

Thanks.

Ang Beepeng
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Passing array of float from Squeak to C

Yoshiki Ohshima-2
At Fri, 20 Feb 2009 03:11:20 -0800 (PST),
Ang Beepeng wrote:

>
>
> I'm facing problem to pass a float array over to C, to create a plugin.
>
> Previously, I use variableWordSubclass: to create a class to store floats,
> in an array. It works fine, as floats are stored as words.
> Now that I need to have an instance variable, I use variableSubclass: to
> store floats. It seems like floats are being stored as object in the array
> this time. The VM crashes when I try to use to same method to access to the
> float array.

  To get a Float object and use the value in C, use #floatValueOf:.
Look at the senders of the method for examples.

-- Yoshiki

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Passing array of float from Squeak to C

Joshua Gargus-2
Yoshiki Ohshima wrote:
At Fri, 20 Feb 2009 03:11:20 -0800 (PST),
Ang Beepeng wrote:
  
I'm facing problem to pass a float array over to C, to create a plugin. 

Previously, I use variableWordSubclass: to create a class to store floats,
in an array. It works fine, as floats are stored as words.
Now that I need to have an instance variable, I use variableSubclass: to
store floats. It seems like floats are being stored as object in the array
this time. The VM crashes when I try to use to same method to access to the
float array.
    

  To get a Float object and use the value in C, use #floatValueOf:.
Look at the senders of the method for examples.
  

I'm not sure that this is the right thing, since each Float represents a double-precision floating point number, and the contents of FloatArray are single-precision.

I would look at the primitives in CroquetPlugin, which you can find in an OpenCroquet or Cobalt image.  For example, #primitiveTransformVector3 transforms a 3-element vector by a 4x4 matrix.  Matrix4x4 and Vector3 are both subclasses of FloatArray.

This might still not be answering your question directly (since you are talking about adding inst-vars to a 'variable-word' class).  My suggestion would be add another inst-var to hold a separate FloatArray object which contains your floating point data.

Josh


-- Yoshiki

  



Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Passing array of float from Squeak to C

Yoshiki Ohshima-2
At Fri, 20 Feb 2009 12:44:23 -0800,
Joshua Gargus wrote:

>
> [1  <multipart/alternative (7bit)>]
> [1.1  <text/plain; ISO-8859-1 (7bit)>]
>
> [1.2  <text/html; ISO-8859-1 (7bit)>]
> Yoshiki Ohshima wrote:
>
>     At Fri, 20 Feb 2009 03:11:20 -0800 (PST),
>     Ang Beepeng wrote:
>
>         I'm facing problem to pass a float array over to C, to create a plugin.
>        
>         Previously, I use variableWordSubclass: to create a class to store floats,
>         in an array. It works fine, as floats are stored as words.
>         Now that I need to have an instance variable, I use variableSubclass: to
>         store floats. It seems like floats are being stored as object in the array
>         this time. The VM crashes when I try to use to same method to access to the
>         float array.
>
>       To get a Float object and use the value in C, use #floatValueOf:.
>     Look at the senders of the method for examples.
>
> I'm not sure that this is the right thing, since each Float represents a double-precision floating point number, and the
> contents of FloatArray are single-precision.

> I would look at the primitives in CroquetPlugin, which you can find in an OpenCroquet or Cobalt image.  For example, #
> primitiveTransformVector3 transforms a 3-element vector by a 4x4 matrix.  Matrix4x4 and Vector3 are both subclasses of
> FloatArray.

  Yes, I may be just misunderstanding what he wants.  Though, he did
have a variant of MatrixPlugins that manipulates FloatArrays already,
and now going to have some additional data involved in the
computation.  So I thought he want to have a way to get that
additional data that is stored as Squeak's Float.

> This might still not be answering your question directly (since you are talking about adding inst-vars to a
> 'variable-word' class).  My suggestion would be add another inst-var to hold a separate FloatArray object which contains
> your floating point data.

  Yes, that would do, too.

-- Yoshiki