Project

sizes

0.0
No commit activity in last 3 years
No release in over 3 years
A very simple gem that exposes the C *sizeof* keyword to Ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.2.9
 Project Readme

sizes¶ ↑

A very simple gem that exposes the C sizeof keyword to Ruby.

This does not check the memory footprint of a given Ruby object. I may implement that sometime in the future if it’s really needed, but for now this gem is only useful for checking primitive C types such as float, short, and so on.

I wrote this because I couldn’t find any cross-platform way to get these sizes from within Ruby. If it exists, then I’ve just reinvented the wheel, but at least I’m documenting it. :)

Installation¶ ↑

gem install sizes

Usage¶ ↑

require 'sizes'
import Sizes
sizeof(:short)
#=> 2

The sizeof method can also be called as a module function:

require 'sizes'
Sizes.sizeof(:float)
#=> 4

More info¶ ↑

Arguments to the #sizeof method can be either symbols or strings, and must be one of the following supported types:

:char
:unsigned_char
:signed_char
:signed_int
:int
:signed_short_int
:signed_long_int
:long_int
:long
:unsigned_int
:unsigned
:unsigned_short_int
:unsigned_short
:unsigned_long_int
:unsigned_long
:float
:double
:long_double
:int8            
:int16           
:int32           
:int64           
:uint8           
:uint16          
:uint32          
:uint64          
:int_least8      
:int_least16     
:int_least32     
:int_least64     
:uint_least8     
:uint_least16    
:uint_least32    
:uint_least64    
:int_fast8       
:int_fast16      
:int_fast32      
:int_fast64      
:uint_fast8      
:uint_fast16     
:uint_fast32     
:uint_fast64     
:intptr          
:uintptr         
:intmax          
:uintmax         
:size_t, :size   
:wchar_t, :wchar

As you can see, some types are represented more than once with varying names. This is purely for convenience.

If the argument does not appear in the above list, an ArgumentError will be raised.

Note on Patches/Pull Requests¶ ↑

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Colin MacKenzie IV. See LICENSE for details. thoughtsincomputation.com