hi ! i am having a problem with declaring a 3 dimensional array !!
can any one help me declare
a[150][25000][150] ;
in C++. can it be possible ? plz help me thanks !
hi ! i am having a problem with declaring a 3 dimensional array !!
can any one help me declare
a[150][25000][150] ;
in C++. can it be possible ? plz help me thanks !
>a[150][25000][150] ;
I seriously doubt you need an array this large. If you do then you have some design issues to hammer out before writing anything.
-Prelude
My best code is written with the delete key.
You can't need a array that big, that array has twice as many elements as there are people living in the United States.
Describe what you are trying to do and maybe we can suggest a better solution to your problem.
well what i am trying to do is that i am sorting a file of 25000 elements with a max of 150 letters per number. now when i read a number then i can store it in a[0][0][1...150] by reference to its length so that i dont have to make any comparison for variable length digits. suppose that i have a number of 50 length then i can store it at a[50[0][1...50] , no when another number of 5 length comes then ican store it in a[50][1][1...50] ... so in this way i will be able to make less comparisons as ill already know that the elemnts at a[50][..][...] are less greater than a[49][..][..] so ill save comparisons. and if all the elemenst are of same size then i have to store them in say a[30][1....25000][30]. this is what i am trying to do !!!
well.. your array declaration should always begin with a "int" or "char" or whatever..
Premature optomization is the root of all evil. Try this.
The load takes about 5 seconds on a slow machine the slowest sort took was 0.7 seconds and I don't understand that one, it takes ~0.4 seconds usually. My test file was about 2 megs 25000 random strings of random length from 1 to 150.Code:#include<string> #include<algorithm> #include<vector> #include<iostream> #include<fstream> using std::cout; using std::endl; bool cmp(const std::string &a,const std::string &b) { if(a.size()<b.size()) return true; else if(a.size()>b.size()) return false; else return (a<b); } int main() { std::vector<std::string> strings; cout << "loading" << endl; std::ifstream in("bigfile"); while(!in.eof()) { std::string str; getline(in,str); strings.push_back(str); } cout << "sorting" << endl; std::sort(strings.begin(),strings.end(),cmp); cout << "done" << endl; }
theres an formula somewhere that helps you reference all the elements with just one variable.. that if the numers all fit in hex or something lol.
Ok, I get it. What you're trying to do makes sence speed wise, but unfortunatly you have to live within the memory limits of the computer as well.Originally posted by Array_troubled
well what i am trying to do ...
One option would be to use some Linked Lists instead of all arrays so that you will not have to allocate memory until it is needed to hold something; of course however, this will take more time to index then an array would.
grib.... i don't have the include files that you have mentioned.... is this code for VC???? i need this sorting to work in Turbo C++ ... can i do it somehow????? please reply as soon as possible...
Perhaps you can try using dynamic memory allocation using the new operator and pointers.
i would like to know what is happening. what elements are you sorting? why are there so many? and is it worth all this fuss?
but without knowing a single thing, the best advice i could give for large arrays is to sort it in small blocks. sort a block, then either output it to file or screen, and forget about it. there's no way you can keep it all at once. but do tell me what the whole idea is.
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials