Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Memory Size

Memory Size

Scheduled Pinned Locked Moved C / C++ / MFC
helphardwaredata-structuresperformancetutorial
4 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    emrosa
    wrote on last edited by
    #1

    Hello...I'm declaring a class array of size 80,000,000...when compiling there is an error that the size exceeds the allowed one and the program may not run. I tried but it really does not work..it says that the program is not a win32 application. My solution is to declare the class array dynamically: myclass1 = new myclass[size] When I tried with this there is no memory allocated and the program aborts. As myclass has some double data and other classes embedded, I guess I need to overload the operator new so to create the needed space. Can anyone help me how to do this, assuming the class is defined as: class myclass{ public: myclass2 curr_data2; myclass3 curr_data3; myclass2 new_data4; myclass3 new_data5; } and the other classes class myclass2{ public: double x; double y; double z; } class myclass3{ public{ double motionX; double motionY; double motionZ; } Thanks, Eric Manuel Rosales Pena Alfaro PhD student Unversity of Essex Wivenhoe Park Colchester, CO4 3SQ Essex, Uk email: emrosa@essex.ac.uk tel: +44-01206-87311

    C D N 3 Replies Last reply
    0
    • E emrosa

      Hello...I'm declaring a class array of size 80,000,000...when compiling there is an error that the size exceeds the allowed one and the program may not run. I tried but it really does not work..it says that the program is not a win32 application. My solution is to declare the class array dynamically: myclass1 = new myclass[size] When I tried with this there is no memory allocated and the program aborts. As myclass has some double data and other classes embedded, I guess I need to overload the operator new so to create the needed space. Can anyone help me how to do this, assuming the class is defined as: class myclass{ public: myclass2 curr_data2; myclass3 curr_data3; myclass2 new_data4; myclass3 new_data5; } and the other classes class myclass2{ public: double x; double y; double z; } class myclass3{ public{ double motionX; double motionY; double motionZ; } Thanks, Eric Manuel Rosales Pena Alfaro PhD student Unversity of Essex Wivenhoe Park Colchester, CO4 3SQ Essex, Uk email: emrosa@essex.ac.uk tel: +44-01206-87311

      C Offline
      C Offline
      Chris Meech
      wrote on last edited by
      #2

      A quick calculation yields that for the array alone, the program will use approximately 3.6G of memory. I think you need to re-think your array size to bring it down to a much smaller number. Chris Meech "what makes CP different is the people and sense of community, things people will only discover if they join up and join in." Christian Graus Nov 14, 2002. "Microsoft hasn't ever enforced its patents. Apparently they keep them for defensive reasons only. Or, they could be waiting 'til they have a critical mass of patents, enforce them all at once and win the game of Risk that they're playing with the world." Chris Sells Feb 18, 2003.

      1 Reply Last reply
      0
      • E emrosa

        Hello...I'm declaring a class array of size 80,000,000...when compiling there is an error that the size exceeds the allowed one and the program may not run. I tried but it really does not work..it says that the program is not a win32 application. My solution is to declare the class array dynamically: myclass1 = new myclass[size] When I tried with this there is no memory allocated and the program aborts. As myclass has some double data and other classes embedded, I guess I need to overload the operator new so to create the needed space. Can anyone help me how to do this, assuming the class is defined as: class myclass{ public: myclass2 curr_data2; myclass3 curr_data3; myclass2 new_data4; myclass3 new_data5; } and the other classes class myclass2{ public: double x; double y; double z; } class myclass3{ public{ double motionX; double motionY; double motionZ; } Thanks, Eric Manuel Rosales Pena Alfaro PhD student Unversity of Essex Wivenhoe Park Colchester, CO4 3SQ Essex, Uk email: emrosa@essex.ac.uk tel: +44-01206-87311

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        The default stack size is 1MB, hence the compiler error. Allocating much more than that (100s of MBs) from the heap is possible but I would still question the need. That's not to say that a need doesn't actually exist, but to just nonchalantly ask the OS for GBs, or even MBs, of memory all at once is questionable.

        1 Reply Last reply
        0
        • E emrosa

          Hello...I'm declaring a class array of size 80,000,000...when compiling there is an error that the size exceeds the allowed one and the program may not run. I tried but it really does not work..it says that the program is not a win32 application. My solution is to declare the class array dynamically: myclass1 = new myclass[size] When I tried with this there is no memory allocated and the program aborts. As myclass has some double data and other classes embedded, I guess I need to overload the operator new so to create the needed space. Can anyone help me how to do this, assuming the class is defined as: class myclass{ public: myclass2 curr_data2; myclass3 curr_data3; myclass2 new_data4; myclass3 new_data5; } and the other classes class myclass2{ public: double x; double y; double z; } class myclass3{ public{ double motionX; double motionY; double motionZ; } Thanks, Eric Manuel Rosales Pena Alfaro PhD student Unversity of Essex Wivenhoe Park Colchester, CO4 3SQ Essex, Uk email: emrosa@essex.ac.uk tel: +44-01206-87311

          N Offline
          N Offline
          Nitron
          wrote on last edited by
          #4

          easy dude, that's pretty nuts. are you sure you NEED 80 MILLION of your class thingy's, or are you just allocating that many "to be on the safe side" ? I suggest you look into std::vector. It just may provide all the answers you seek. i.e., if you need another one of your classes, just do something like:

          std::vector<MyClass*> vpMyClass;

          for(int i=0; i<iSomeNumberOfNeededClasses; i++)
          vpMyClass.push_back(new CMyClass);

          just remember to delete everything and empty the vector when you're done. - Nitron


          "Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups