Archived

This topic is now archived and is closed to further replies.

Maximum size of literal values

This topic is 5273 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Guest Anonymous Poster
There is no such thing in the standard as "infinite". Any type has a size. The type of "x" is, I believe, size_t, which is typically a 32-bit unsigned integer on common x86 CPUs. However, the CPU can''t address more than 32 bits'' worth of bytes in a linear fashion, and each int is 4 bytes, so that gives you 30 bits'' worth, or about 1 billion. However, the heap can''t grow that big, because most OS-es set aside half of linear memory for the kernel, leaving 29 bits of addressing or about 0.5 billion ints. Then you need space for your .exe and the .dlls it uses, so a more reasonable achievable maximum is something like 250 million ints.

On a 64-bit architecture, these numbers go up, of course :-)

Share this post


Link to post
Share on other sites
Reserving that much memory takes AGES to do. I remember where at a point I tried to determine the max amount of int''s I could declare in a dynamic array. Took me about 2 minutes before it was done allocating it. I should try it again, maybe it was the setup of the computer.

Toolmaker



-Earth is 98% full. Please delete anybody you can.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Dear me!

void * ptr = new int[x]

Would this type mismatch even compile? I don''t have access to vc++ right now to check.

quote:

Assuming infinite memory? Well, the maximum value the variable type of x can hold, then.



I didn''t mean for x to be a C++ variable. I meant it to be a literal value like this... int[60000]

What I''m trying to get at is does c++ allow literal values in code which are too big to fit into any basic type?

Share this post


Link to post
Share on other sites