 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
KK Guest
|
Posted: Thu Nov 18, 2004 12:47 am Post subject: What is the maximum memory available for allocation in a pro |
|
|
Greetings,
Please correct me if I am wrong.
The pointer is a 32 bit data type, hence the maximum memory that can
be allocated in a program is 2^32 bytes. Although that is a large
piece of memory available, what about hypothetical applications which
demand larger memory requirements?
I dont understand why basic text books dont talk about the memory size
that a pointer data type would occupy?(i.e., 32 bits in this case) I
think it is certainly a fundemental thing to learn to understand
pointers better.
Thank you for your time and consideration,
-KK
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Timo Geusch Guest
|
Posted: Thu Nov 18, 2004 12:12 pm Post subject: Re: What is the maximum memory available for allocation in a |
|
|
KK was seen penning the following ode to ... whatever:
| Quote: | Greetings,
Please correct me if I am wrong.
The pointer is a 32 bit data type, hence the maximum memory that can
be allocated in a program is 2^32 bytes.
|
You're jumping to conclusions here IMHO. The maximum memory available
to your process is usually governed by other constraints like hardware
platform and operating system more than the maximum address space you
can access using a pointer. Nobody guarantees that one pointer is
enough to access all your application's address space (see 'segmented
architectures'), either, so the size of the pointer has at best a
passing resemblance to the size of the address space it can use.
That said, your assumption that a pointer is a 32 bit value is just
plain wrong - it depends on the platform that you're using, and can be
just about any size. To illustrate this, in the course of a day I tend
to use computers that have pointer sizes running from 16 to 64 bit,
with some interesting intermediate sizes available on some of them.
AFAIK the C++ standard doesn't make any guarantee that a pointer has
the capability to address a certain amount of memory.
--
Timo Geusch
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Falk Tannhäuser Guest
|
Posted: Fri Nov 19, 2004 12:46 pm Post subject: Re: What is the maximum memory available for allocation in a |
|
|
KK wrote:
| Quote: | The pointer is a 32 bit data type, hence the maximum memory that can
be allocated in a program is 2^32 bytes. [...]
I dont understand why basic text books dont talk about the memory size
that a pointer data type would occupy?(i.e., 32 bits in this case) I
think it is certainly a fundemental thing to learn to understand
pointers better.
|
When I was young , I worked on machines where pointers had sometimes
only 16 bits (sometimes 32 bits depending on compiler options, but
letting me address 2^20 bytes only - but these machines physically had
only 640 kB of memory and this was considered enough for everyone...).
There are machines with pointers occupying 18, 36, 48 ... bits, too.
There are even machines on which sizeof(int*) < sizeof(char*).
All this is highly implementation dependent, which is why "basis text
books" supposed to teach C++ in a platform independent way usually
should not teach you to make assumptions about the size of pointers
or the size of available memory space.
Falk
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Thomas Richter Guest
|
Posted: Fri Nov 19, 2004 12:51 pm Post subject: Re: What is the maximum memory available for allocation in a |
|
|
Hi,
| Quote: | Please correct me if I am wrong.
The pointer is a 32 bit data type,
|
"You are wrong". (-; Who says that a pointer is a 32 bit type? The
C++ standard clearly doesn't. Your compiler vendor might say that, but
then if you have an application that requires more memory, you'd better
switch to an architecture with longer pointers and a compiler suitable
for it. AMD64 has 64 bit pointers, for example.
| Quote: | I dont understand why basic text books dont talk about the memory size
that a pointer data type would occupy?(i.e., 32 bits in this case)
|
Because it isn't defined, and you shouldn't need to care about the
internal representation of a pointer.
So long,
Thomas
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Branimir Maksimovic Guest
|
Posted: Fri Nov 19, 2004 12:57 pm Post subject: Re: What is the maximum memory available for allocation in a |
|
|
[email]kewlkarun (AT) yahoo (DOT) com[/email] (KK) wrote in message news:<c8fd5039.0411171337.7d8fc55 (AT) posting (DOT) google.com>...
| Quote: | Greetings,
Please correct me if I am wrong.
The pointer is a 32 bit data type, hence the maximum memory that can
be allocated in a program is 2^32 bytes.
|
The pointer is not 32 bit data type on all systems, even on 32 bit
systems it can be bigger(eg segment selector+32bit offset).
Resulting address can be bigger then value that can be stored
in 32 bit data type.
Although that is a large
| Quote: | piece of memory available, what about hypothetical applications which
demand larger memory requirements?
|
This is system/hardware dependant.
| Quote: | I dont understand why basic text books dont talk about the memory size
that a pointer data type would occupy?(i.e., 32 bits in this case) I
think it is certainly a fundemental thing to learn to understand
pointers better.
|
Because, it is not relevant to basic text books.
Greetings, Bane.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Michiel Salters Guest
|
Posted: Fri Nov 19, 2004 12:58 pm Post subject: Re: What is the maximum memory available for allocation in a |
|
|
[email]kewlkarun (AT) yahoo (DOT) com[/email] (KK) wrote in message news:<c8fd5039.0411171337.7d8fc55 (AT) posting (DOT) google.com>...
| Quote: | Greetings,
Please correct me if I am wrong.
The pointer is a 32 bit data type, hence the maximum memory that can
be allocated in a program is 2^32 bytes.
|
No it isn't. The pointer is a datatype that is up to sizeof(void*)
bytes. Common values are 16, 32 or 64.
| Quote: | Although that is a large piece of memory available, what about
hypothetical applications which demand larger memory requirements?
|
Nothing hypothetical about that. Databases often use more. There
are half a dozen processor types which use 64 bit pointers internally.
| Quote: | I dont understand why basic text books dont talk about the memory size
that a pointer data type would occupy?(i.e., 32 bits in this case) I
think it is certainly a fundemental thing to learn to understand
pointers better.
|
Because they would be wrong in many cases. If you need to know, ask
the compiler. Only textbooks that cover one compiler can be explicit,
but that would of course limit their market.
Regards,
Michiel Salters
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ulrich Eckhardt Guest
|
Posted: Fri Nov 19, 2004 12:59 pm Post subject: Re: What is the maximum memory available for allocation in a |
|
|
KK wrote:
| Quote: | Please correct me if I am wrong.
The pointer is a 32 bit data type,
|
Wrong. Common architectures have pointers from 8 to 64 bits(though I'm not
aware of a C++ or even C compiler for 8 bit CPUs).
| Quote: | hence the maximum memory that can be allocated in a program is 2^32
bytes.
|
Well, only theoretically. Reason being that this memory would start at
address 0 and range to address 0xffffffff, thus somewhere including the
null pointer. But that is just academical.
Much more real is the fact that most OSs won't let you have so much memory.
| Quote: | Although that is a large piece of memory available, what about
hypothetical applications which demand larger memory requirements?
|
Like for example DVD authoring software? On 32 bit systems, those usually
work with tricks. Even on those systems you can have a type that specifies
a byte inside the data, just that the data usually resides on disk and
parts of it are loaded into the process' memory on demand. On 64 bit
systems you can load the whole DVD image into your process' memory and
access via normal pointers.
If you wonder how such large amounts of data are handled efficiently, take
a look at the (POSIX?) mmap() call, which (given proper support) speeds up
things a lot.
| Quote: | I dont understand why basic text books dont talk about the memory size
that a pointer data type would occupy?(i.e., 32 bits in this case) I
think it is certainly a fundemental thing to learn to understand
pointers better.
|
I do believe that they talk about that, hopefully explicitly stating that
their size is system dependant.
BTW: almost all things here are not directly related to C++ but rather how
common computers with common multitasking OSs work.
Uli
--
Questions ?
see C++-FAQ Lite: http://parashift.com/c++-faq-lite/ first !
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
kanze@gabi-soft.fr Guest
|
Posted: Fri Nov 19, 2004 3:03 pm Post subject: Re: What is the maximum memory available for allocation in a |
|
|
[email]kewlkarun (AT) yahoo (DOT) com[/email] (KK) wrote in message
news:<c8fd5039.0411171337.7d8fc55 (AT) posting (DOT) google.com>...
| Quote: | The pointer is a 32 bit data type,
|
That depends on the implementation. On most architectures today, I
think, it is a 64 bit data type, although PC's and IBM mainframes still
use 32 bits, and Unisys mainframes 36.
| Quote: | hence the maximum memory that can be allocated in a program is 2^32
bytes.
|
Not necessarily. First, the maximum that can be allocated at any one go
is not necessarily the maximum that can be allocated totally: most
people over 30 have probably worked on systems where the maximum for any
single allocation was 2^16 (minus a few), around 64K, where as the total
available was 640K. Secondly, just because the address range means that
that the addresses can exist doesn't mean that the memory, or even the
virtual memory is there -- my system has 64 bit pointers, but my machine
is only configured for 1MB virtual memory, and the maximum amount I can
allocate is less than that (since other things, like the OS itself)
occupy memory. And of course, back in the good old days, lots of
processors had less bits on the address bus than pointers had in memory.
And of course, some older systems with 32 bits pointers used the top
bits for various special purposes (VAX, for example).
| Quote: | Although that is a large piece of memory available, what about
hypothetical applications which demand larger memory requirements?
|
If you need more memory than the system allows, you have two choices,
get a bigger machine, or manage some sort of virtual addressing
yourself. Generally, the first solution will be a lot, lot cheaper (you
can get an awful lot of machine for $20K or $30K -- which won't buy a
whole lot of programming work), as well as giving much, much better
performance.
| Quote: | I dont understand why basic text books dont talk about the memory size
that a pointer data type would occupy?
|
Probably because it varies so from one machine to the next.
| Quote: | (i.e., 32 bits in this case) I think it is certainly a fundemental
thing to learn to understand pointers better.
|
I don't really see why. You do have to know that memory isn't infinite,
and that your code has to be prepared for allocations to fail, but most
programmer don't need anything beyond that.
--
James Kanze GABI Software http://www.gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Antoun Kanawati Guest
|
Posted: Fri Nov 19, 2004 4:06 pm Post subject: Re: What is the maximum memory available for allocation in a |
|
|
KK was seen penning the following ode to ... whatever:
| Quote: | Greetings,
Please correct me if I am wrong.
The pointer is a 32 bit data type, hence the maximum memory that can
be allocated in a program is 2^32 bytes.
|
Back when pointers where made of two 16-bit values, I couldn't go over
20 bits of address space.
On the other hand, with the modern intel boxes, you have two 32-bit
values to make addresses with. So, the 32-bits you're talking about
are not necessarily the full width of the address space.
And, just to make life more interesting, sometimes the 32-bits are
bigger than the available space. For example, look at the various
Linux kernel build options.
Finally, you can set limits on resource use for every program, just
before it runs (on many platforms).
Which leaves us with no single answer to the question.
--
A. Kanawati
[email]NO.antounk.SPAM (AT) comcast (DOT) net[/email]
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Allan W Guest
|
Posted: Fri Nov 19, 2004 4:09 pm Post subject: Re: What is the maximum memory available for allocation in a |
|
|
[email]kewlkarun (AT) yahoo (DOT) com[/email] (KK) wrote
| Quote: | Greetings,
Please correct me if I am wrong.
The pointer is a 32 bit data type,
|
Wrong. A pointer is 16 bits, unless you use so-called "Far pointers"
which are 32 bits, or "Huge pointers" which are also 32 bits but they
work correctly for large objects at the expense of being more compute-
intensive. The exception is if you compile
....No wait, I meant to say that a pointer is 24 bits.
Sorry, you werre right in the first place: A pointer is 32 bits, but
this is the address of a 16-bit word (which is also the size of a
character), so the program actually can use 2^33 bytes.
My friend, who works on embedded systems, assures me that you only need
12 bits for a pointer, because the CPU can't go beyond 4096 bytes of
memory anyway.
No, wait! It turns out that a pointer is 64 bits!
....or is it?
[SNIP]
| Quote: | I dont understand why basic text books dont talk about the memory size
that a pointer data type would occupy?(i.e., 32 bits in this case) I
think it is certainly a fundemental thing to learn to understand
pointers better.
|
*ahem* The size of a pointer is system-dependant, meaning that depends
on which compiler (and platform) you are using. The documentation for
your compiler should tell you what the pointer size is, but you would be
wise to pretend that you just don't know, unless you absolutely need to
make your program depend on what system it is using.
Your hypothetical example might perhaps be a good example of that
absolute need... if your program needs more than 4Gb of RAM to operate,
then your program will either need to find ways to use very-large
pointers (when running on systems that are capable of giving your
program more than 4Gb at a time), or else you will need to find ways
to "swap out" your data to some storage until it is needed, and then
"swap it back in." (Fortunately, some operating systems do this
automatically.)
Furthermore, just because your program seems to need 20Gb of RAM, and
you happen to HAVE more than 20Gb of RAM on some computer, doesn't
mean that you shouldn't try to redesign your program so that it doesn't
waste so much memory space. Consider sparse arrays and other data
structures that aren't so huge!
In any case, this is an advanced topic that does not belong in "basic
text books."
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Robert Simac Guest
|
|
| Back to top |
|
 |
Francis Glassborow Guest
|
Posted: Sat Nov 20, 2004 4:14 pm Post subject: Re: What is the maximum memory available for allocation in a |
|
|
In article <c8fd5039.0411171337.7d8fc55 (AT) posting (DOT) google.com>, KK
<kewlkarun (AT) yahoo (DOT) com> writes
| Quote: | Please correct me if I am wrong.
The pointer is a 32 bit data type, hence the maximum memory that can
be allocated in a program is 2^32 bytes. Although that is a large
piece of memory available, what about hypothetical applications which
demand larger memory requirements?
I dont understand why basic text books dont talk about the memory size
that a pointer data type would occupy?(i.e., 32 bits in this case) I
think it is certainly a fundemental thing to learn to understand
pointers better.
|
The memory available to your program has little if anything to do with
pointers. There are two requirements in C++ (also in C). The first is
that a void* (which must be layout compatible with char*) must be able
to represent any 'address' used by your program.
The second is that no pointer value may be used unless it is one of the
following:
The address of an object of a compatible type to that of the pointer
The address of one more than the above (often referred to as 'one beyond
the end')
The address of a function (note that this may be an entirely different
address space to that for data and there is no requirement that a void*
can represent such an address)
A null pointer of the appropriate type.
Note that the language allows objects to be inspected and traversed by
use of an unsigned char* (it cannot be traversed with a void* though a
void* is allowed to point into an object) but that is still not a
licence to examine memory that is not part of an existing object (and
that excludes 'one beyond the end')
All other pointer values are invalid and may not be used in a portable
program.
Quite separately an implementation may document what are valid locations
for objects.
As C++ requires that the programmer can use a pointer to all potential
objects, the size of a pointer type limits the range of memory that can
be used (so if you are using segmented memory, you will need to use
pointers that include the segment 'address' and the implementation must
provide those for you if your program uses more than a single segment)
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Stephen Toledo-Brown Guest
|
Posted: Sat Nov 27, 2004 4:02 am Post subject: Re: What is the maximum memory available for allocation in a |
|
|
[email]kanze (AT) gabi-soft (DOT) fr[/email] wrote:
| Quote: | kewlkarun (AT) yahoo (DOT) com (KK) wrote in message
news:<c8fd5039.0411171337.7d8fc55 (AT) posting (DOT) google.com>...
That depends on the implementation. On most architectures today, I
think, it is a 64 bit data type, although PC's and IBM mainframes still
use 32 bits, and Unisys mainframes 36.
|
For C++ purposes, current IBM mainframes can use 32 bit or 64 bit
addressing. For other languages, there may also be 24 bit and 31 bit
addressing. All these can be used on the same machine at the same time.
Also, 32 bit Unix and 64 bit x86 architectures are both quite common at
the moment.
More interestingly, on OS/400 and its successors, pointers are built
into the operating system itself, and are much more strongly checked
than in most other systems. I've never worked with them directly myself,
but I have frequently had to write multi-platform code which must work
on OS/400. Naive assumptions about the format/interpretation of pointers
on this platform tend to be exposed quite quickly!
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
kanze@gabi-soft.fr Guest
|
Posted: Tue Nov 30, 2004 9:58 pm Post subject: Re: What is the maximum memory available for allocation in a |
|
|
Stephen Toledo-Brown <browns (AT) uk (DOT) ibm.com> wrote
| Quote: | kanze (AT) gabi-soft (DOT) fr wrote:
[email]kewlkarun (AT) yahoo (DOT) com[/email] (KK) wrote in message
news:<c8fd5039.0411171337.7d8fc55 (AT) posting (DOT) google.com>...
That depends on the implementation. On most architectures today, I
think, it is a 64 bit data type, although PC's and IBM mainframes
still use 32 bits, and Unisys mainframes 36.
For C++ purposes, current IBM mainframes can use 32 bit or 64 bit
addressing. For other languages, there may also be 24 bit and 31 bit
addressing.
|
OK. It's been awhile since I've been concerned with IBM mainframes. At
the time, they were maximum 32 bit addressing (although the addressing
modes were a bit strange, which meant that in some languages, you
couldn't use all of the bits).
| Quote: | All these can be used on the same machine at the same time. Also, 32
bit Unix and 64 bit x86 architectures are both quite common at the
moment.
|
I'm not sure what you mean by x86 -- for me, x86 is IA-32, which means
either 32 or 48 bit pointers at the hardware level. IA-64, of course,
allows 64 bit pointers.
As for Unix, I'm not up to date on the Power PC architecture, but Sparc
and the HP's (both the ex-Compac/ex-Digital Alphas and the newer IA-64
based HP's) all support 64 bit pointers. For the most part, the
compilers have options which allow compiling in 32 bit mode as well, if
only to avoid breaking old code, which "assumed" that pointers were 32
bit ints. In many cases, of course, these modes also result in faster
programs (because smaller programs and better locality), and so are
often used even when old code isn't an issue.
| Quote: | More interestingly, on OS/400 and its successors, pointers are built
into the operating system itself, and are much more strongly checked
than in most other systems. I've never worked with them directly
myself, but I have frequently had to write multi-platform code which
must work on OS/400. Naive assumptions about the format/interpretation
of pointers on this platform tend to be exposed quite quickly!
|
Back to the good old days, huh? When sizeof(char*) != sizeof(int*).
(Actually, there are several "good old days". One, which I learned in,
where word addressed machines were common, and we even knew about
machines which didn't use two's complement. And another, where all the
world was a VAX, and as an old .sig said, "men were men, women were
women and pointers were ints.")
--
James Kanze GABI Software http://www.gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|