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
help-smalltalk@gnu.org
http://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to