my question is that i have 512 mb ram .What is the max integer array size that i can declare in c.
I recently experimented with different values and found that while i am able to create large values of array size the moment i use them i get "segmentation fault" error.
All i know is that the answer is related to the actual stack size in my computer..
can someone help me???
18 5597
There is no hard and fast answer for this. It changes dynamically.
(I am writing this but not that confident about it. Never Read it any where just worked out)
say your compiler is x bit compiler.
Now try
MaxArraySize=pow(2,x-1)-1
(I Believe it will work best for char type.)
MaxArraySize=(pow(2,x-1))/(sizeof specific_variable_type)-1
(This will work for diff variable type)
Let me know if I am wrong.
Regards,
Johny
The amount of memory you can allocate isn't going to be something you can easily compute unless your operating system has a very specific and deterministic memory model.
Most OS use virtual memory and also allow over committing or memory requests in order to make life easy and let things run. For instance if you have 512MB ram your OS may let you ask for 1GB ram with a series of malloc or new requests.
If you want to understand more a search for memory management or over commit or some such may be helpful.
Also many OSes have memory swap to the harddisk. So theoretically you could have an array that is the maximum size of both your memory and hard disk, but that would never fly.
Thanks a lot everybody.....Actually i am going to post something i was told by someone but still i would like to know if its correct.
The max array size depends on 2 things...OS and Ram size....There's a fixed stack size in our memory for each os and we can increase the size from the heap to it....So the max size of array is actually fixed for each computer but can be changed to infinity......
No thats nonsense. i think you would be better off doing some realistic C++ programming instead of pursuing these these way out theories.
uhmm...thanks for the reply but i need to find the max array size for the programming so......i need to find the answer......
What are you actually trying to program?
Maybe we can help you better achieve your goal if we know what your desired end result is, and all this talk of maximum possible array size might not be pertinent to whatever task you're trying to undertake.
Banfa 9,065
Expert Mod 8TB
There may be a platform dependant answer to your question "what is the maximum array size" but it would be just that, platform dependant. Since you have not specified the platform (giving the RAM size is not a specification of the platform, at the very least you would need to add processor and operating system and toolchain) the question remains unanswerable.
Furthermore your array could be allocated, static or automatic. So in every case, you need first of all to make sure your compiler has allocated enough space by its own settings for the stack or the heap, depending on how this array is declared.
But anyway answers could be theoretical on some situations. Because if you have a 512MB RAM but your running processes are using 100MB, then the maximum size would be (512-100)/sizeof(int).
okay first of all i have found that i can easily make an array size of 200000 so as to make people realise that the answer is not as short as range of int etc....
My OS is windows Xp with 2.6 Ghz intel proccesor.
I am actually trying to find the complexities of various algorithms and for it i need to go as large as possible....Now one option is simply declaring dynamically and putting numbers randomly...i know about it.....
I only wanted to ask if someone knew how much numbers can i put theoretically in a fixed static integer array......
@nk28
If you want to find the complexity of an algorithm why don't you use "infinity" instead of trying to figure out what your system can do.
However, using infinity brings you into the realm of pure mathematics and computation complexity theory and away from the application of those two domains.
I suggest you do a bit of reading on a topic like "Big O notation"
(see: http://en.wikipedia.org/wiki/Big_O_notation)
Banfa 9,065
Expert Mod 8TB
Well in theory then you should be able to have any integer array of approximately
2 Gigabytes / sizeof(int) = 536,870,912
You wont be able to attain this actual number as some memory will be used for other program variables, heap and stack. If you reserve a megabyte for that which is plenty if you are careful then you get 536,608,768.
The physical memory size is on no consequence as Windows uses a page file to supplement physical memory but you would have to make sure your page file was configured to expand if required (up to 2-3 gigbytes should do it).
That number would be the largest number that you could use whether the array was static, on the stack or on the heap. In Windows both the stack and heap of a program expand as required but the stack, heap and static data all have to fit into the virtual address space that reserves 2 gigabytes of virtual address space for user data (as opposed to system data which also has 2 gigabytes of virtual address space reserved).
Yes that is all true, however as soon as you move to a different platform/compiler/computer/hardware/anything your results become invalid.
If you want to know the true complexity of an algorithm you need to express it mathematically using some kind of notation.
Banfa 9,065
Expert Mod 8TB
That is true RedSon but if you want to allocate a stupidly large array of integers then approximately 500,000,000 is your limit on a Windows system.
P.S. That definately works on Linux I just tested it on my 768Mbyte system with 2Gbyte swap drive and it ran fine with such a large array albeit slowly due to all the swapping.
Heh, I'm impressed that you actually tested it out.
Banfa 9,065
Expert Mod 8TB
What are we always telling people. If you want to know if it works compile an run it yourself :D Bizarrely it took longer to compile (several minutes with my computer completely locked up) than run (~40seconds with my computer just responding very slowly). That was with a static array I suspect you would different results with the array on the heap.
[EDIT]
Data on Heap
Compile: A few seconds
Run: 60 Seconds
Data on Stack
Compile: A few seconds
Run: Segmentation Fault (may be Linux programs can't handle 2 Gbytes on the stack)
Check your compiler flags, I but you could find a setting in there to help you with the stack size.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Trevor Best |
last post by:
I did a test once using a looping variable, first dimmed as Integer,
then as Long. I found the Integer was quicker at looping. I knew this to
be true back in the 16 bit days where the CPU's (80286)...
|
by: Jeff |
last post by:
Hello everybody,
I'm kind of new to C programming, but here's a little question.
Usually, when you have an array of chars, you put a \0 at the end of
it to terminate the string. That way, it is...
|
by: shailashri_sk |
last post by:
Hi,
int *p;
p++; here p now increments itself with the size of integer.
similarly,
I wanted to know, how to declare an pointer to an array ( say array of
integers)
where in it we do a p++ it...
|
by: GS |
last post by:
The stdint.h header definition mentions five integer categories,
1) exact width, eg., int32_t
2) at least as wide as, eg., int_least32_t
3) as fast as possible but at least as wide as, eg.,...
|
by: henrytcy |
last post by:
Hi,
How can I convert integer, for example 12113, to char array but without
specify an array size in C programming?
Thanks!
|
by: kujahleague |
last post by:
Been bothering me so long, we can find the size of string array (array of char) but what is the way to find the size for integer array? I've tried using while loop until it find '\0' null character,...
|
by: desktop |
last post by:
I have this code:
void test(int* array)
{
int pp = sizeof(array);
cout << pp << endl;
}
|
by: Ivan K. |
last post by:
I am looking at some legacy code, which begins by
allocating a double matrix with the dmatrix()
function from NRC as follows:
double **A, **augin, **augout, **aa;
A = dmatrix(1,...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |