Author
|
Topic: Hey c++ people, I need help
|
coffee_addict
Member (Idle past 507 days) Posts: 3645 From: Indianapolis, IN Joined: 03-29-2004
|
|
Message 1 of 9 (200798)
04-20-2005 10:24 PM
|
|
|
How do I create a very large array (parameter probably around 2 million)? Would making a vector help?
Replies to this message: | | Message 2 by arachnophilia, posted 04-20-2005 10:43 PM | | coffee_addict has not replied | | Message 3 by Asgara, posted 04-20-2005 11:01 PM | | coffee_addict has not replied | | Message 4 by jar, posted 04-20-2005 11:21 PM | | coffee_addict has not replied | | Message 5 by PaulK, posted 04-21-2005 3:00 AM | | coffee_addict has not replied | | Message 6 by Dr Jack, posted 04-21-2005 4:30 AM | | coffee_addict has not replied | | Message 7 by Percy, posted 04-21-2005 2:53 PM | | coffee_addict has replied |
|
arachnophilia
Member (Idle past 1373 days) Posts: 9069 From: god's waiting room Joined: 05-21-2004
|
very large array a very large grant from nasa.
This message is a reply to: | | Message 1 by coffee_addict, posted 04-20-2005 10:24 PM | | coffee_addict has not replied |
|
Asgara
Member (Idle past 2332 days) Posts: 1783 From: Wisconsin, USA Joined: 05-10-2003
|
NOT a C++ person ( more of a C- - )
Codeguru Vector would be used for dynamic array. If you don't know the exact parameter I would say that yes a vector is called for. I am NOT a C++ person, but I have read that HUGE arrays have problems unless you use some kind of dynamic allocation. Page not found - CUJ Loans
Asgara "Embrace the pain, spank your inner moppet, whatever....but get over it" select * from USERS where CLUE > 0 http://asgarasworld.bravepages.comhttp://perditionsgate.bravepages.com
This message is a reply to: | | Message 1 by coffee_addict, posted 04-20-2005 10:24 PM | | coffee_addict has not replied |
|
jar
Member (Idle past 424 days) Posts: 34026 From: Texas!! Joined: 04-20-2004
|
What are you going to do with this array? Is it transient or permanent, one unit or fields? Aslan is not a Tame Lion
This message is a reply to: | | Message 1 by coffee_addict, posted 04-20-2005 10:24 PM | | coffee_addict has not replied |
|
PaulK
Member Posts: 17828 Joined: 01-10-2003 Member Rating: 2.3
|
I'm not really a C++ person (yet) but it looks to me as if the potential problems are going to be with the implementation and not with the language itself. My advice is: 1) Work out how much memory you are going to need (check the sixe of the individual elements - an integer is going to be 4 bytes on almost any system so 2,000,000 integers comes to 8MB). Don't forget to allow for all the rest of your variables. 2) Check the compiler documentation and release notes for limits on memory usage. That's the only place you are likely to find it.
This message is a reply to: | | Message 1 by coffee_addict, posted 04-20-2005 10:24 PM | | coffee_addict has not replied |
|
Dr Jack
Member Posts: 3514 From: Immigrant in the land of Deutsch Joined: 07-14-2003 Member Rating: 8.3
|
You could create it the same way you create any other array... although personally I'd be more inclined to use std: eque - std::vector won't help as the standard effectively guarantees it to be a continuous block of memory, so it's no better than a C array in terms of memory fragmentation. Relevant questions: What's it to be an array of? Is it to be a one-dimensional array? Why do you want such a frickin' big array? What access characteristics do you need from it? edit: Bloody overactive smiley-maker This message has been edited by Mr Jack, 04-21-2005 10:27 AM
This message is a reply to: | | Message 1 by coffee_addict, posted 04-20-2005 10:24 PM | | coffee_addict has not replied |
|
Percy
Member Posts: 22505 From: New Hampshire Joined: 12-23-2000 Member Rating: 4.9
|
Mr. Jack is precisely correct. std: eque is the best approach for large arrays because it doesn't allocate contiguous memory. Two million is not a particularly large vector. I've used deque's of size one million with no problem. One word of caution. If your array type is a builtin like int or char then std: eque or std: eque is fine, but if it's an aggregate type you might find better performance if you store pointers to your object instead of the object itself, avoiding many, many calls to copy constructors, e.g., std:eque. The questions that others raised are good, too. Depending upon your application, a large array may not be the best approach. For example, if you have to search your array you may find std::map<> better suited since it uses a hash for quick lookups. --Percy
|
coffee_addict
Member (Idle past 507 days) Posts: 3645 From: Indianapolis, IN Joined: 03-29-2004
|
|
Message 8 of 9 (200952)
04-21-2005 3:03 PM
|
Reply to: Message 7 by Percy 04-21-2005 2:53 PM
|
|
On a second thought, screw array or vector. I just figured out how to do this without creating an array that big. By the way, my mistake. It's actually 3 million, not 2. All I have to do now is write the subroutine. I'm doing an analysis with the Galileo data taken during its 3 years orbiting Jupiter (it measured stuff every 38 seconds for 3 years). It's a project I'm working with a professor. Hopefully, I can get some stuff published in the near future
This message is a reply to: | | Message 7 by Percy, posted 04-21-2005 2:53 PM | | Percy has not replied |
|
Dr Jack
Member Posts: 3514 From: Immigrant in the land of Deutsch Joined: 07-14-2003 Member Rating: 8.3
|
|
Message 9 of 9 (201093)
04-22-2005 4:24 AM
|
Reply to: Message 7 by Percy 04-21-2005 2:53 PM
|
|
For example, if you have to search your array you may find std::map<> better suited since it uses a hash for quick lookups. std::map doesn't use a hash for quick lookups it uses a tree structure (usually a red-black tree), if you want hash mapping you need the non-standard hash_map included with most popular STL libraries.
This message is a reply to: | | Message 7 by Percy, posted 04-21-2005 2:53 PM | | Percy has not replied |
|