Sizes 1.0 released

C

Colin Mackenzie iv

I've just released a new gem called "sizes".

This is a very simple gem that exposes "sizeof" to Ruby to enable
checking size of primitive types like :float, :unsigned_int, and so
forth. I needed this for a parser I was writing, (I didn't feel like
writing the whole thing in C), couldn't find a way to do it without an
extension, and saw no reason not to publish the code afterward. :)

I hope I didn't just reinvent something that already exists in core Ruby
-- but I couldn't find it if it does, no matter how hard I Googled.

Documentation and source code:
http://github.com/sinisterchipmunk/sizes

-Colin MacKenzie IV
http://thoughtsincomputation.com
 
A

Ammar Ali

I've just released a new gem called "sizes".

This is a very simple gem that exposes "sizeof" to Ruby to enable
checking size of primitive types like :float, :unsigned_int, and so
forth. I needed this for a parser I was writing, (I didn't feel like
writing the whole thing in C), couldn't find a way to do it without an
extension, and saw no reason not to publish the code afterward. :)

I hope I didn't just reinvent something that already exists in core Ruby
-- but I couldn't find it if it does, no matter how hard I Googled.

Documentation and source code:
http://github.com/sinisterchipmunk/sizes

-Colin MacKenzie IV
http://thoughtsincomputation.com

Cool. It would be nice to add the C99 type names, like int8, uint32, etc..

Cheers,
Ammar
 
J

Jeremy Bopp

I've just released a new gem called "sizes".

This is a very simple gem that exposes "sizeof" to Ruby to enable
checking size of primitive types like :float, :unsigned_int, and so
forth. I needed this for a parser I was writing, (I didn't feel like
writing the whole thing in C), couldn't find a way to do it without an
extension, and saw no reason not to publish the code afterward. :)

I hope I didn't just reinvent something that already exists in core Ruby
-- but I couldn't find it if it does, no matter how hard I Googled.

Documentation and source code:
http://github.com/sinisterchipmunk/sizes

I think this sort of functionality may already be available as part of
the ffi gem:

irb(main):001:0> require 'ffi'
irb(main):002:0> FFI::TypeDefs[:int].size
=> 4
irb(main):003:0> FFI::TypeDefs[:int8].size
=> 1
irb(main):004:0> FFI::TypeDefs[:uint].size
=> 4
irb(main):005:0> FFI::TypeDefs[:int64].size
=> 8
irb(main):006:0> FFI::TypeDefs[:float].size
=> 4

-Jeremy
 
C

Colin Mackenzie iv

Cool. It would be nice to add the C99 type names, like int8,
uint32, etc..
Cheers, Ammar

Done! Just pushed v1.1 including the additional types. See the
documentation (again).

I think this sort of functionality may already be available as
part of the ffi gem:

Sweet. I knew something like this had to exist, but got tired of
googling. I spent more time looking than I did coding my own! :)

Thanks for the replies,
-Colin MacKenzie IV
http://thoughtsincomputation.com
@sinisterchipmnk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top