help-smalltalk
[Top][All Lists]
Advanced

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

[Help-smalltalk] Re: Questions regarding CArray's


From: Paolo Bonzini
Subject: [Help-smalltalk] Re: Questions regarding CArray's
Date: Sun, 17 Oct 2010 10:55:46 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100907 Fedora/3.1.3-1.fc13 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.3

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



reply via email to

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