puzzlecracker wrote:
I waas just asked by interviewer the number of bytes 2 short int and
virtual function take on 32 bit machine as well as 64 bit machine...
what is the difference?
Perhaps other people will benefit, so here it is:
=-Word Size-=
In general, an N-bit machine has a "word" size of N-bits.
The "word" is its native unit for processing.
So a 16-bit machine would have 16-bits in its word,
a 32-bit machine would have 32-bits in its word and
so on.
=-Alignment-=
Many processors operate most effectively (and efficiently)
when their data is aligned on a boundary, usually the
same width as their word size. Some processors can
handle other alignments, some not.
A 32-bit processor with a 32-bit word size would like
its data on 32-bit boundaries. If there are 8-bits
in a byte, then this processor would like its data
to start on 4-byte boundaries or where:
(address % 4) == 0
The processor can obtain this data with one fetch.
Data on other addresses would cause multiple fetches
or the processor would generate an exception error.
Word size and alignment requirements may not be
the same. It is possible for a processor to have
a 16-bit word size, but require data on 32-bit
alignment.
For character data, some processors may fetch many
characters at once and disregard the ones it doesn't
need.
For more information, use your favorite search
engine and search the newsgroups for "alignment".
http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=word
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq:
http://www.parashift.com/c++-faq-lite
C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library