[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

testing for 64-bit environment

Tom

12/28/2007 3:15:00 AM

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

11 Answers

Tom

12/28/2007 3:59:00 AM

0

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
>


yermej

12/28/2007 4:16:00 AM

0

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.

Rob Biedenharn

12/28/2007 4:37:00 AM

0


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:

irb> Object::PLATFORM
=> "universal-darwin9.0"
irb> 1.size
=> 4
irb> (2**30 - 1).class
=> Fixnum
irb> (2**30 - 1).size
=> 4
irb> (2**31 - 1).class
=> Bignum
irb> (2**31 - 1).size
=> 4
irb> (2**32 - 1).size
=> 4
irb> (2**33 - 1).size
=> 8
irb> (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://agileconsult...
Rob@AgileConsultingLLC.com



Rob Biedenharn

12/28/2007 4:38:00 AM

0

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.

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://agileconsult...
Rob@AgileConsultingLLC.com




Justin Collins

12/28/2007 5:05:00 AM

0

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 =3D `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 =20
>>> system is 64-bit? i need to load a different module for different =20
>>> 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:
>
> irb> Object::PLATFORM
> =3D> "universal-darwin9.0"
> irb> 1.size
> =3D> 4
> irb> (2**30 - 1).class
> =3D> Fixnum
> irb> (2**30 - 1).size
> =3D> 4
> irb> (2**31 - 1).class
> =3D> Bignum
> irb> (2**31 - 1).size
> =3D> 4
> irb> (2**32 - 1).size
> =3D> 4
> irb> (2**33 - 1).size
> =3D> 8
> irb> (2**33 - 1).class
> =3D> 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=09=09http://agileconsult...
> Rob@AgileConsultingLLC.com

irb(main):001:0> RUBY_PLATFORM
=3D> "x86_64-linux"
irb(main):002:0> 1.size
=3D> 8


-Justin


Tom

12/28/2007 6:36:00 AM

0

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:
>>
>> irb> Object::PLATFORM
>> => "universal-darwin9.0"
>> irb> 1.size
>> => 4
>> irb> (2**30 - 1).class
>> => Fixnum
>> irb> (2**30 - 1).size
>> => 4
>> irb> (2**31 - 1).class
>> => Bignum
>> irb> (2**31 - 1).size
>> => 4
>> irb> (2**32 - 1).size
>> => 4
>> irb> (2**33 - 1).size
>> => 8
>> irb> (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://agileconsult...
>> Rob@AgileConsultingLLC.com
>
> irb(main):001:0> RUBY_PLATFORM
> => "x86_64-linux"
> irb(main):002:0> 1.size
> => 8
>
>
> -Justin
>
>

Luis Lavena

12/28/2007 2:54:00 PM

0

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:
>
> > irb> Object::PLATFORM
> > => "universal-darwin9.0"
> > irb> 1.size
> > => 4
> > irb> (2**30 - 1).class
> > => Fixnum
> > irb> (2**30 - 1).size
> > => 4
> > irb> (2**31 - 1).class
> > => Bignum
> > irb> (2**31 - 1).size
> > => 4
> > irb> (2**32 - 1).size
> > => 4
> > irb> (2**33 - 1).size
> > => 8
> > irb> (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://agileconsult...
> > R...@AgileConsultingLLC.com
>
> irb(main):001:0> RUBY_PLATFORM
> => "x86_64-linux"
> irb(main):002:0> 1.size
> => 8
>

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

Koni Marti

12/29/2007 1:14:00 AM

0

>>> 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

Thomas Hurst

12/29/2007 2:28:00 AM

0

* Koni Marti (KMarti@gmx.ch) wrote:

> 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.

--
Thomas 'Freaky' Hurst
http...

Luis Lavena

12/29/2007 3:40:00 AM

0

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?
>

That how gcc implements it, but on windows:

Type 32 bit 64 bit
------------------------------
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