testing for 64-bit environment

T

Tom Metge

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
 
Y

yermej

in case anyone else is wondering, my solution:

arch = `uname -i`

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

Rob Biedenharn

in case anyone else is wondering, my solution:

arch = `uname -i`

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://agileconsultingllc.com
(e-mail address removed)
 
R

Rob Biedenharn

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://agileconsultingllc.com
(e-mail address removed)
 
J

justincollins

Quoting Rob Biedenharn said:
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://agileconsultingllc.com
(e-mail address removed)

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


-Justin
 
T

Tom Metge

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

Tom
 
L

Luis Lavena

Quoting Rob Biedenharn <[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
 
K

Koni Marti

(e-mail address removed)
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
 
T

Thomas Hurst

* Koni Marti ([email protected]) said:
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.
 
L

Luis Lavena

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
 
J

Jan Dvorak

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

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
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top