Questions regarding CArray's

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

Questions regarding CArray's

Holger Freyther
Hi,

for a test case I would like to create a C Array.

I want to do something like:
(#(1 2 3) asByteArray asCObject: (CArrayCType from: #byte)) at: 0

so somehow my CArrayCType from: #byte is wrong. I should be able to find the
equivalent of <declaration: #( #(#name #array 3))>, if you lack the time I am
going to search more and will find the solution myself.

thanks.

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Questions regarding CArray's

Paolo Bonzini-2
On 10/16/2010 09:29 PM, Holger Hans Peter Freyther wrote:

> Hi,
>
> for a test case I would like to create a C Array.
>
> I want to do something like:
> (#(1 2 3) asByteArray asCObject: (CArrayCType from: #byte)) at: 0
>
> so somehow my CArrayCType from: #byte is wrong. I should be able to find the
> equivalent of<declaration: #( #(#name #array 3))>, if you lack the time I am
> going to search more and will find the solution myself.

First of all, I should point out that #asCData: mallocs a block that
contains the _whole_ ByteArray.

Given this, I suggest you don't use CArrayCType, because a CObject is a
pointer and there is very little difference between:

1) a pointer to the first byte:

    #[1 2 3] asCData: CByteType

2) a pointer to a 3-byte array:

    #[1 2 3] asCData: (CByteType arrayType: 3)

I suggest using the former, for which I added a shortcut #asCData in
git, together with a similar shortcut for Strings: ('123' asCData) is
the same as ('123' asCData: CCharType).

Alternatively,

   #[1 2 3] castTo: CByteType

creates the same thing, but backed by GC memory and with range checking.

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Questions regarding CArray's

Holger Freyther
On 10/17/2010 10:55 AM, Paolo Bonzini wrote:

>
> I suggest using the former, for which I added a shortcut #asCData in git,
> together with a similar shortcut for Strings: ('123' asCData) is the same as
> ('123' asCData: CCharType).
>

Thanks. I have added a very primitive testcase for these methods.

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

0001-Add-test-code-for-the-new-asCData-selector.patch (1K) Download Attachment