[MacRuby] #1080: Add #size method for C struct classes

MacRuby ruby-noreply at macosforge.org
Mon Dec 27 08:15:04 PST 2010


#1080: Add #size method for C struct classes
---------------------------------+------------------------------------------
 Reporter:  kyossi212@…          |       Owner:  lsansonetti@…        
     Type:  enhancement          |      Status:  new                  
 Priority:  major                |   Milestone:                       
Component:  MacRuby              |    Keywords:  C struct sizeof      
---------------------------------+------------------------------------------
 To use some sort of C-based API,  It will helpful if MacRuby has
 capability of obtaining byte-size for C struct classes.

 NSRect.size in ruby code should be same as sizeof(NSRect) in c code.



 Use case example:

 AudioStreamGetPropertyInfo() in CoreAudio.framework returns required byte-
 size for it's outSize(4th argument).

 {{{
 extern OSStatus AudioStreamGetPropertyInfo(
     AudioStreamID inStream,
     UInt32 inChannel,
     AudioDevicePropertyID inPropertyID,
     UInt32*outSize, /*total byte-size for required data in subsequence
 call*/
     Boolean*outWritable);
 }}}

 for some inPropertyID enum value , outSize indicate total byte size for (
 an array of some structure interested in).
 So, to get actual data (by subsequent call to AudioStreamGetProperty), we
 should calculate required array length, to allocate buffer.
 {{{
 p=Pointer.new(StructFoo, outSize/StructFoo.size)
 }}}

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/1080>
MacRuby <http://macruby.org/>



More information about the macruby-tickets mailing list