quick question

Started by
4 comments, last by SirLuthor 18 years, 4 months ago
me and my buddy were talking and i was wondering...is there a maximum number of "cells" an array can hold? i heard it was 256?
Advertisement
what exactly do you mean by 'cells'? If you are asking how big an array can be, i.e. how much memory can a single array hold then the answer is theoretically infinite. There is no law (that i'm aware of) stopping you from creating one array from all available system memory. I have seen an array of 1000000 chars before (of course this was only for testing reasons and served no true purpose). hope that helps.
Quote:Original post by willthiswork89
me and my buddy were talking and i was wondering...is there a maximum number of "cells" an array can hold? i heard it was 256?
No, that's certainly not true. The actual max array size will probably depend on whether you create it on the heap or the stack, as well as other possibly platform- or compiler-specific factors, but it will generally be orders of magnitude greater than 256.
If you are using C++ use std::vector rather than arrays (unless you have a good reason to use an array). In which case here's some code that'll answer your question
#include <vector>#include <iostream>using namespace std;int main(){    vector<int> foo;    // output the maximum number of elements foo can hold    cout << foo.max_size() << endl;}


If you're stuck with C, i'm not sure what the answer to your question is, but i'm sure that it is much higher than 256.
yea because im making a 2d game and i want the levels to be big..didnt know how big they can be
Let's put it this way. They can be big enough for anything you could possibly do [grin] Don't worry about hitting some theoretical boundary at which arrays stop, there is no such thing, as long as you have the physical memory, you can use it.
Free speech for the living, dead men tell no tales,Your laughing finger will never point again...Omerta!Sing for me now!

This topic is closed to new replies.

Advertisement