Testing for 64-bit environment

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

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.

···

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

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

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

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

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

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

-Justin

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
> R...@AgileConsultingLLC.com

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

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

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
    http://hur.st/

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

Luis

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

Luis