Thread: Vector their size and declarations

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    50

    Vector their size and declarations

    This line unexpectedly prompted error message:

    vector<long> pixred68(end68),pixgreen68(end68),pixblue68(end68) ,Redrect68(end68),Greenrect68(end68), Bluerect68(end68);

    Wherein am I mistaken? Is it because of the length of declarataion? Is it because of the integer end68 which has the value of 277205850? If it is what should I do?
    I need vectors of that size!!!

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    perinent code would help but my first thoughts would be you aren't indicating where to find the vector class by not indicated the namespace with either a using namespace std; declaration or using the std:: scope resolution syntax before the declaration.
    Code:
    #include <iostream>
    #include <vector>
     
    int main()
    {
      long end68 = 277205850;
     
      std::vector<long> v;
      v.push_back(end68);
      std::cout << v.front();
      std::cin.get();
      return 0;
    }
    compiles and runs fine on my compiler.
    Last edited by elad; 12-27-2004 at 11:53 AM.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    I'll address the ridiculous first:

    >Is it because of the integer end68 which has the value of 277205850? I need vectors of that size!!!
    You need six vectors of 277205850 long integers... Okay, let's assume that a long int is four bytes, just for the sake of argument. That means you want to take up 6652940400 bytes of memory for your vectors, not including internal storage for the container objects. Does this seem a little unusual to you?

    You don't need all of that memory. There are many ways to optimize for storage. Yeesh.

    >Wherein am I mistaken?
    In your logic.
    My best code is written with the delete key.

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    First off, nice sig prelude. Secondly, what exactly (and i mean very specifically explain) are you attempting to do? You are aware that your machine doesn't have unlimited RAM, correct?

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    I suggest you buy a Cray if that's what you really need...

  6. #6
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    If you are just trying to initialize each of those vectors with a single element with the value of end68, then you are using the wrong vector constructor. Either use elad's method, or try this:
    Code:
    vector<long> pixred68(1, end68), pixgreen68(1, end68), pixblue68(1, end68);
    It constructs each vector and initializes them with 1 element containing the value of end68.

  7. #7
    Registered User
    Join Date
    Dec 2004
    Posts
    50

    Vectors

    I want to declare six vectors each having end68 elements. In the course of the further calculalation I will assign values to each element of every vector but I cannot pass this declaration line because I always get message error. <vector> and using namespace std are also in the programm, but for the sake of brevity, I left them out.


    TO PRELUDE:
    I THOUGHT THE PURPOSE OF THIS MESSAGE BOARD IS TO HELP PEOPLE TO SOLVE THEIR PROBLEMS AND NOT TO SERVE CERTAIN INDIVIDUALS TO SHOW HOW MUCH THEY AND HOW LITTLE OTHERS KNOW ABOUT C++. NEXT TIME I WOULD REALLY APPRECIATE SOME CONSTRUCTIVE SUGGESTIONS; KEEP DISDAINFUL REMARKS FOR YOURSELF.

  8. #8
    Registered User Kybo_Ren's Avatar
    Join Date
    Sep 2004
    Posts
    136
    She is not being disdainful. She is telling you that even if you get it to compile, it will not work. On most platforms, the maximum amount of virtual memory you can allocate is 4GB. Thus, your program will crash and burn.


    I'd recommend redesigning your algorithms so you use less memory, and THEN worrying about getting them to initialize properly (which will be easy; these posts already here tell you how).

    EDIT: Gender assumptions removed
    Last edited by Kybo_Ren; 12-28-2004 at 07:14 PM.

  9. #9
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    >> NEXT TIME I WOULD REALLY APPRECIATE SOME CONSTRUCTIVE SUGGESTIONS; KEEP DISDAINFUL REMARKS FOR YOURSELF.

    I would say that this is a constructive suggestion! Allocating some 6 GB of RAM (which is probably more than your computer would handle) is just bad!

  10. #10
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    For one, think about following Preludes way of programming. You cannot write a program comsuming that much memory, because your computer will most likely not be able to handle it. If you don't have a supercomputer at home, you will need another algorithm.

    Another way to a solution, how about posting the real error message as a quote ? I still fail to see why your code shouldn't compile.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  11. #11
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    I agree with nvoigt; the following code compiles fine for me:
    Code:
    #include <vector>
    
    using std::vector;
    
    const long end68 = 277205850;
    
    int main(int argc, char *argv[])
    {
    	vector<long> pixred68(end68), pixgreen68(end68), pixblue68(end68),
    		Redrect68(end68), Greenrect68(end68), Bluerect68(end68);
    
    	return 0;
    }
    I'll admit that I don't have the hardware to run such a program. Post the real error message along with the code.

    Kybo_Ren> Prelude's not a he.
    Last edited by pianorain; 12-28-2004 at 08:06 AM.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  12. #12
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I cannot pass this declaration line because I always get message error.
    Is your error when you try to compile, or when you try to run the program? Also, what compiler are you using and on what operating system?
    TO PRELUDE:
    I THOUGHT THE PURPOSE OF THIS MESSAGE BOARD IS TO HELP PEOPLE TO SOLVE THEIR PROBLEMS AND NOT TO SERVE CERTAIN INDIVIDUALS TO SHOW HOW MUCH THEY AND HOW LITTLE OTHERS KNOW ABOUT C++. NEXT TIME I WOULD REALLY APPRECIATE SOME CONSTRUCTIVE SUGGESTIONS; KEEP DISDAINFUL REMARKS FOR YOURSELF.
    Blah blah blah. Just because you couldn't see it doesn't mean I wasn't being helpful. How am I supposed to help you solve your problem when it's obvious that your program is flawed at a fundamental level, but you only give me a declaration to work with? If you want a better suggestion, ask a smarter question.
    My best code is written with the delete key.

  13. #13
    Never Exist Hermitsky's Avatar
    Join Date
    Jul 2004
    Posts
    149
    first, i never complain to the person who tried to help me, no matter actully they solved the problem or not, i appreciate them.

    second, almost everyone on this forum knows that prelude is a good and kind programmer, always give a great help.


    strickey, i think what you said is really not polite ....

    blow me ... ...

  14. #14
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    TO PRELUDE:
    I THOUGHT THE PURPOSE OF THIS MESSAGE BOARD IS TO HELP PEOPLE TO SOLVE THEIR PROBLEMS AND NOT TO SERVE CERTAIN INDIVIDUALS TO SHOW HOW MUCH THEY AND HOW LITTLE OTHERS KNOW ABOUT C++. NEXT TIME I WOULD REALLY APPRECIATE SOME CONSTRUCTIVE SUGGESTIONS; KEEP DISDAINFUL REMARKS FOR YOURSELF
    The only thing disdainful here is that you are trying to allocate memory on a PC sufficient enough to run the national defense system, compute weather forecasts, and launch the space shuttle into orbit.

    If you know anything about protected mode programming you must know that since your system does not have 6GB of RAM, it will be swapping like a mad man to the hard drive thus making your program run god awful slow. I'm thinking there's a better way.

    BTW, it's not polite to scorn respected members of the board. We sorta like Prelude around here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Little Array Difficulty
    By G4B3 in forum C Programming
    Replies: 16
    Last Post: 03-19-2008, 12:59 AM
  2. Enum declarations in resource file
    By Ktulu in forum Windows Programming
    Replies: 3
    Last Post: 11-27-2007, 03:26 PM