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, 9:59 pm, Tom M. [email protected] wrote:

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, 2007, at 10:59 PM, Tom M. wrote:

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> (230 - 1).class
=> Fixnum
irb> (2
30 - 1).size
=> 4
irb> (231 - 1).class
=> Bignum
irb> (2
31 - 1).size
=> 4
irb> (232 - 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 B. http://agileconsultingllc.com
[email protected]

Quoting Rob B. [email protected]:

irb> (2**31 - 1).class
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 B. http://agileconsultingllc.com
[email protected]

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

-Justin

On Dec 27, 2007, at 11:20 PM, yermej wrote:

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 B. http://agileconsultingllc.com
[email protected]

On Dec 28, 2:05 am, [email protected] wrote:

arch = uname -i

tom
irb> (2**30 - 1).class
=> 8
Rob B. http://agileconsultingllc.com
[email protected]

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

[email protected]
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

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

Tom

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.

On Saturday 29 December 2007 04:45:06 Luis L. 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

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 Dec 28, 10:14 pm, Koni M. [email protected] wrote:

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

Luis

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs