# Testing for 64-bit environment

**URL:** <https://rubytalk.org/t/testing-for-64-bit-environment/43357>\
**Category:** ruby-talk\
**Created:** [28 December 2007 03:15 UTC](https://rubytalk.org/t/testing-for-64-bit-environment/43357 "2007-12-28T03:15:24Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Metge](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@Thomas\_Metge](https://rubytalk.org/u/Thomas_Metge)\
**Post date:** [28 December 2007 03:15 UTC](https://rubytalk.org/t/testing-for-64-bit-environment/43357/1 "2007-12-28T03:15:24Z")

</div>

subject says it all- anyone know a way to determine if the host system is 64-bit? i need to load a different module for different environments.

thanks,  
tom

---

<div class="post-metadata">

**Author:** ![Thomas\_Metge](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@Thomas\_Metge](https://rubytalk.org/u/Thomas_Metge)\
**Post date:** [28 December 2007 03:59 UTC](https://rubytalk.org/t/testing-for-64-bit-environment/43357/2 "2007-12-28T03:59:03Z")

</div>

in case anyone else is wondering, my solution:

arch = `uname -i`

tom

> **···**
>
> On Dec 27, 2007, at 8:15 PM, Tom Metge wrote:
> 
> > subject says it all- anyone know a way to determine if the host system is 64-bit? i need to load a different module for different environments.
> > 
> > thanks,  
> > tom

---

<div class="post-metadata">

**Author:** ![yermej](https://avatars.discourse-cdn.com/v4/letter/y/b2d939/32.png) [@yermej](https://rubytalk.org/u/yermej)\
**Post date:** [28 December 2007 04:20 UTC](https://rubytalk.org/t/testing-for-64-bit-environment/43357/3 "2007-12-28T04:20:13Z")

</div>

You might want to use the constant RUBY\_PLATFORM for better  
portability. On our x86\_64 Linux box, uname -i only returns  
AuthenticAMD with no indication that it's 64 bit. On Windows, -i isn't  
a valid option for uname.

> **···**
>
> On Dec 27, 9:59 pm, Tom Metge \<t...@accident-prone.com\> wrote:
> 
> > in case anyone else is wondering, my solution:
> > 
> > arch = `uname -i`
> > 
> > tom
> > 
> > On Dec 27, 2007, at 8:15 PM, Tom Metge wrote:
> > 
> > \> subject says it all- anyone know a way to determine if the host  
> > \> system is 64-bit? i need to load a different module for different  
> > \> environments.
> > 
> > \> thanks,  
> > \> tom

---

<div class="post-metadata">

**Author:** ![Rob\_Biedenharn1](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@Rob\_Biedenharn1](https://rubytalk.org/u/Rob_Biedenharn1)\
**Post date:** [28 December 2007 04:36 UTC](https://rubytalk.org/t/testing-for-64-bit-environment/43357/4 "2007-12-28T04:36:37Z")

</div>

> in case anyone else is wondering, my solution:
> 
> arch = `uname -i`
> 
> tom
> 
> > subject says it all- anyone know a way to determine if the host system is 64-bit? i need to load a different module for different environments.
> > 
> > thanks,  
> > tom

I only have a 32-bit system to try, but the Pickaxe seems to indicate that Fixnum.size is the bytes in the machine representation of a Fixnum.

On my Intel MacBookPro:

> Object::PLATFORM

=\> "universal-darwin9.0"

> 1.size

=\> 4

> (2\*\*30 - 1).class

=\> Fixnum

> (2\*\*30 - 1).size

=\> 4

> (2\*\*31 - 1).class

=\> Bignum

> (2\*\*31 - 1).size

=\> 4

> (2\*\*32 - 1).size

=\> 4

> (2\*\*33 - 1).size

=\> 8

> (2\*\*33 - 1).class

=\> Bignum

Note that Fixnum can hold 31 bits (30 + sign bit) and Bignum jumps from 4 bytes to 8 bytes.

What do you get for 1.size on a 64-bit platform?

-Rob

Rob Biedenharn [http://agileconsultingllc.com](http://agileconsultingllc.com)  
Rob@AgileConsultingLLC.com

> **···**
>
> On Dec 27, 2007, at 10:59 PM, Tom Metge wrote:
> 
> > On Dec 27, 2007, at 8:15 PM, Tom Metge wrote:

---

<div class="post-metadata">

**Author:** ![Rob\_Biedenharn1](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@Rob\_Biedenharn1](https://rubytalk.org/u/Rob_Biedenharn1)\
**Post date:** [28 December 2007 04:38 UTC](https://rubytalk.org/t/testing-for-64-bit-environment/43357/5 "2007-12-28T04:38:27Z")

</div>

It's not a valid option on Mac OS X either (and there's no other option to uname that indicates the word-size of the CPU).

-Rob

Rob Biedenharn [http://agileconsultingllc.com](http://agileconsultingllc.com)  
Rob@AgileConsultingLLC.com

> **···**
>
> On Dec 27, 2007, at 11:20 PM, yermej wrote:
> 
> > On Dec 27, 9:59 pm, Tom Metge \<t...@accident-prone.com\> wrote:
> > 
> > > in case anyone else is wondering, my solution:
> > > 
> > > arch = `uname -i`
> > > 
> > > tom
> > > 
> > > On Dec 27, 2007, at 8:15 PM, Tom Metge wrote:
> > > 
> > > > subject says it all- anyone know a way to determine if the host  
> > > > system is 64-bit? i need to load a different module for different  
> > > > environments.
> > > 
> > > > thanks,  
> > > > tom
> > 
> > You might want to use the constant RUBY\_PLATFORM for better  
> > portability. On our x86\_64 Linux box, uname -i only returns  
> > AuthenticAMD with no indication that it's 64 bit. On Windows, -i isn't  
> > a valid option for uname.

---

<div class="post-metadata">

**Author:** ![Justin\_Collins](https://avatars.discourse-cdn.com/v4/letter/j/3e96dc/32.png) [@Justin\_Collins](https://rubytalk.org/u/Justin_Collins)\
**Post date:** [28 December 2007 05:05 UTC](https://rubytalk.org/t/testing-for-64-bit-environment/43357/6 "2007-12-28T05:05:04Z")

</div>

Quoting Rob Biedenharn \<Rob@AgileConsultingLLC.com\>:

> > in case anyone else is wondering, my solution:
> > 
> > arch = `uname -i`
> > 
> > tom
> > 
> > > subject says it all- anyone know a way to determine if the host system is 64-bit? i need to load a different module for different environments.
> > > 
> > > thanks,  
> > > tom
> 
> I only have a 32-bit system to try, but the Pickaxe seems to indicate  
> that Fixnum.size is the bytes in the machine representation of a Fixnum.
> 
> On my Intel MacBookPro:
> 
> \> Object::PLATFORM  
> =\> "universal-darwin9.0"  
> \> 1.size  
> =\> 4  
> \> (2\*\*30 - 1).class  
> =\> Fixnum  
> \> (2\*\*30 - 1).size  
> =\> 4  
> \> (2\*\*31 - 1).class  
> =\> Bignum  
> \> (2\*\*31 - 1).size  
> =\> 4  
> \> (2\*\*32 - 1).size  
> =\> 4  
> \> (2\*\*33 - 1).size  
> =\> 8  
> \> (2\*\*33 - 1).class  
> =\> Bignum
> 
> Note that Fixnum can hold 31 bits (30 + sign bit) and Bignum jumps from  
> 4 bytes to 8 bytes.
> 
> What do you get for 1.size on a 64-bit platform?
> 
> -Rob
> 
> Rob Biedenharn [http://agileconsultingllc.com](http://agileconsultingllc.com)  
> Rob@AgileConsultingLLC.com

irb(main):001:0\> RUBY\_PLATFORM  
=\> "x86\_64-linux"  
irb(main):002:0\> 1.size  
=\> 8

-Justin

> **···**
>
> > On Dec 27, 2007, at 10:59 PM, Tom Metge wrote:
> > 
> > > On Dec 27, 2007, at 8:15 PM, Tom Metge wrote:

---

<div class="post-metadata">

**Author:** ![Thomas\_Metge](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@Thomas\_Metge](https://rubytalk.org/u/Thomas_Metge)\
**Post date:** [28 December 2007 06:35 UTC](https://rubytalk.org/t/testing-for-64-bit-environment/43357/7 "2007-12-28T06:35:30Z")

</div>

Much more elegant (not to mention cross platform). Exactly what I was looking for- thanks.

Tom

> **···**
>
> On Dec 27, 2007, at 10:05 PM, justincollins@ucla.edu wrote:
> 
> > Quoting Rob Biedenharn \<Rob@AgileConsultingLLC.com\>:
> > 
> > > On Dec 27, 2007, at 10:59 PM, Tom Metge wrote:
> > > 
> > > > in case anyone else is wondering, my solution:
> > > > 
> > > > arch = `uname -i`
> > > > 
> > > > tom
> > > > 
> > > > On Dec 27, 2007, at 8:15 PM, Tom Metge wrote:
> > > > 
> > > > > subject says it all- anyone know a way to determine if the host system is 64-bit? i need to load a different module for different environments.
> > > > > 
> > > > > thanks,  
> > > > > tom
> > > 
> > > I only have a 32-bit system to try, but the Pickaxe seems to indicate  
> > > that Fixnum.size is the bytes in the machine representation of a Fixnum.
> > > 
> > > On my Intel MacBookPro:
> > > 
> > > \> Object::PLATFORM  
> > > =\> "universal-darwin9.0"  
> > > \> 1.size  
> > > =\> 4  
> > > \> (2\*\*30 - 1).class  
> > > =\> Fixnum  
> > > \> (2\*\*30 - 1).size  
> > > =\> 4  
> > > \> (2\*\*31 - 1).class  
> > > =\> Bignum  
> > > \> (2\*\*31 - 1).size  
> > > =\> 4  
> > > \> (2\*\*32 - 1).size  
> > > =\> 4  
> > > \> (2\*\*33 - 1).size  
> > > =\> 8  
> > > \> (2\*\*33 - 1).class  
> > > =\> Bignum
> > > 
> > > Note that Fixnum can hold 31 bits (30 + sign bit) and Bignum jumps from  
> > > 4 bytes to 8 bytes.
> > > 
> > > What do you get for 1.size on a 64-bit platform?
> > > 
> > > -Rob
> > > 
> > > Rob Biedenharn [http://agileconsultingllc.com](http://agileconsultingllc.com)  
> > > Rob@AgileConsultingLLC.com
> > 
> > irb(main):001:0\> RUBY\_PLATFORM  
> > =\> "x86\_64-linux"  
> > irb(main):002:0\> 1.size  
> > =\> 8
> > 
> > -Justin

---

<div class="post-metadata">

**Author:** ![Luis\_Lavena1](https://avatars.discourse-cdn.com/v4/letter/l/f08c70/32.png) [@Luis\_Lavena1](https://rubytalk.org/u/Luis_Lavena1)\
**Post date:** [28 December 2007 14:55 UTC](https://rubytalk.org/t/testing-for-64-bit-environment/43357/8 "2007-12-28T14:55:04Z")

</div>

Please note that RUBY\_PLATFORM indicates on which platform ruby was  
built, but not the current host platform.

On Windows x64, I can build 32 bits or 64 bits application and run  
them side by side.

One-Click installer reports me i386-mswin32 even that I'm on x64 HOST  
OS.

Luis

> **···**
>
> On Dec 28, 2:05 am, justincoll...@ucla.edu wrote:
> 
> > Quoting Rob Biedenharn \<R...@AgileConsultingLLC.com\>:
> > 
> > \> On Dec 27, 2007, at 10:59 PM, Tom Metge wrote:
> > 
> > \>\> in case anyone else is wondering, my solution:
> > 
> > \>\> arch = `uname -i`
> > 
> > \>\> tom
> > 
> > \>\> On Dec 27, 2007, at 8:15 PM, Tom Metge wrote:
> > 
> > \>\>\> subject says it all- anyone know a way to determine if the host  
> > \>\>\> system is 64-bit? i need to load a different module for different  
> > \>\>\> environments.
> > 
> > \>\>\> thanks,  
> > \>\>\> tom
> > 
> > \> I only have a 32-bit system to try, but the Pickaxe seems to indicate  
> > \> that Fixnum.size is the bytes in the machine representation of a Fixnum.
> > 
> > \> On my Intel MacBookPro:
> > 
> > \> \> Object::PLATFORM  
> > \> =\> "universal-darwin9.0"  
> > \> \> 1.size  
> > \> =\> 4  
> > \> \> (2\*\*30 - 1).class  
> > \> =\> Fixnum  
> > \> \> (2\*\*30 - 1).size  
> > \> =\> 4  
> > \> \> (2\*\*31 - 1).class  
> > \> =\> Bignum  
> > \> \> (2\*\*31 - 1).size  
> > \> =\> 4  
> > \> \> (2\*\*32 - 1).size  
> > \> =\> 4  
> > \> \> (2\*\*33 - 1).size  
> > \> =\> 8  
> > \> \> (2\*\*33 - 1).class  
> > \> =\> Bignum
> > 
> > \> Note that Fixnum can hold 31 bits (30 + sign bit) and Bignum jumps from  
> > \> 4 bytes to 8 bytes.
> > 
> > \> What do you get for 1.size on a 64-bit platform?
> > 
> > \> -Rob
> > 
> > \> Rob Biedenharn [http://agileconsultingllc.com](http://agileconsultingllc.com)  
> > \> R...@AgileConsultingLLC.com
> > 
> > irb(main):001:0\> RUBY\_PLATFORM  
> > =\> "x86\_64-linux"  
> > irb(main):002:0\> 1.size  
> > =\> 8

---

<div class="post-metadata">

**Author:** ![Koni\_Marti](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@Koni\_Marti](https://rubytalk.org/u/Koni_Marti)\
**Post date:** [29 December 2007 01:14 UTC](https://rubytalk.org/t/testing-for-64-bit-environment/43357/9 "2007-12-29T01:14:06Z")

</div>

> > > R...@AgileConsultingLLC.com
> > 
> > irb(main):001:0\> RUBY\_PLATFORM  
> > =\> "x86\_64-linux"  
> > irb(main):002:0\> 1.size  
> > =\> 8

Isn't it a huge wast of memory resources to store every number in 8 bytes? I think about counters or other occasions where 8 bytes are way too much for simple scripts. This may extremely hamper the performance.  
Is there a way to specify the number of bytes for representing numbers?  
Otherwise, it would be useful to extend the Fixnum functionality for that feature; what do you think?

-- Koni

---

<div class="post-metadata">

**Author:** ![Thomas\_Hurst](https://avatars.discourse-cdn.com/v4/letter/t/53a042/32.png) [@Thomas\_Hurst](https://rubytalk.org/u/Thomas_Hurst)\
**Post date:** [29 December 2007 02:28 UTC](https://rubytalk.org/t/testing-for-64-bit-environment/43357/10 "2007-12-29T02:28:08Z")

</div>

> Isn't it a huge wast of memory resources to store every number in 8  
> bytes? I think about counters or other occasions where 8 bytes are way  
> too much for simple scripts. This may extremely hamper the  
> performance.

Unless you've got so many of them that you're swapping, no. And if you  
do have that many, and really really want endless millions of small  
numbers, maybe it's time to look at RubyInline or a C extension where  
you can just do uint16\_t bla[2000000000]. Depending on what you're  
doing, such things have doubtless already been written.

> Is there a way to specify the number of bytes for representing numbers?  
> Otherwise, it would be useful to extend the Fixnum functionality for that  
> feature; what do you think?

For performance/storage, not really possible; Fixnums are, as I  
understand it, stored directly in a (VALUE \*), which is the base type  
for all Ruby objects. Note these are pointers; hence, native word size,  
and thus 8 bytes on 64bit systems.

Of course, the entire point of native 64bit is that they're fast at  
64bits, so I wouldn't worry too much about it.

> **···**
>
> \* Koni Marti (KMarti@gmx.ch) wrote:
> 
> --  
> Thomas 'Freaky' Hurst  
> &nbsp;&nbsp;&nbsp;&nbsp;[http://hur.st/](http://hur.st/)

---

<div class="post-metadata">

**Author:** ![Luis\_Lavena1](https://avatars.discourse-cdn.com/v4/letter/l/f08c70/32.png) [@Luis\_Lavena1](https://rubytalk.org/u/Luis_Lavena1)\
**Post date:** [29 December 2007 03:45 UTC](https://rubytalk.org/t/testing-for-64-bit-environment/43357/11 "2007-12-29T03:45:06Z")

</div>

That how gcc implements it, but on windows:

Type 32 bit 64 bit

> **···**
>
> On Dec 28, 10:14 pm, Koni Marti \<KMa...@gmx.ch\> wrote:
> 
> > \>\>\> R...@AgileConsultingLLC.com  
> > \>\> irb(main):001:0\> RUBY\_PLATFORM  
> > \>\> =\> "x86\_64-linux"  
> > \>\> irb(main):002:0\> 1.size  
> > \>\> =\> 8
> > 
> > Isn't it a huge wast of memory resources to store every number in 8  
> > bytes? I think about counters or other occasions where 8 bytes are way  
> > too much for simple scripts. This may extremely hamper the performance.  
> > Is there a way to specify the number of bytes for representing numbers?  
> > Otherwise, it would be useful to extend the Fixnum functionality for  
> > that feature; what do you think?
> 
> ------------------------------  
> char 8 unchanged  
> short 16 unchanged  
> int 32 unchanged  
> long 32 unchanged  
> long long 64 unchanged  
> pointer 32 64  
> enum 32 unchanged  
> float 32 unchanged  
> double 64 unchanged  
> long double 128 unchanged  
> size\_t 32 64
> 
> int remains 32bits, pointers are now 64 and to get "Bignum" you need  
> to use long long to get 64.
> 
> So someone can say windows is more memory footprint friendly than  
> linux 😉
> 
> Luis

---

<div class="post-metadata">

**Author:** ![Jan\_Dvorak](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Jan\_Dvorak](https://rubytalk.org/u/Jan_Dvorak)\
**Post date:** [29 December 2007 11:42 UTC](https://rubytalk.org/t/testing-for-64-bit-environment/43357/12 "2007-12-29T11:42:32Z")

</div>

Both on 64bit linux gcc and 64bit windows vc the 'int' is 32bit. The only  
difference is that 'long' is 64bit on gcc and other compilers (LP64  
compatibility mode) while 32bit on windows VC (LLP64 mode).

Jan

> **···**
>
> On Saturday 29 December 2007 04:45:06 Luis Lavena wrote:
> 
> > That how gcc implements it, but on windows:  
> > ...  
> > int remains 32bits, pointers are now 64 and to get "Bignum" you need  
> > to use long long to get 64.
> > 
> > So someone can say windows is more memory footprint friendly than  
> > linux 😉
> > 
> > Luis
