Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8877797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:33:17+00:00 2026-06-14T19:33:17+00:00

I wanted to initialize a vector of vectors that contain pointers to Courses. I

  • 0

I wanted to initialize a vector of vectors that contain pointers to Courses. I declared this:

std::vector<std::vector<Course*> > *CSPlan = 
        new std::vector<std::vector<Course*> >(smsNum);

What I wanted to do by this is to have a vector of vectors, each inside vector is a vector that contains pointers to Courses, and I wanted the MAIN vector to be of size int smsNum. Furthermore, I wanted it on the heap.

My questions are:

  1. Are both the main vector AND the inside vectors allocated on the heap? or is it only the MAIN vector is on the heap and its’ indexes are pointers to other smaller vectors on the stack?

  2. I declared it to be of size int smsNum so the Main vector is of size 10, but what about the smaller vectors? are they also of that size or are they still dynamic?

My goal in the end is to have a vector of vectors, both the Main vector and the child vectors on the heap, and ONLY the Main vector is of size smsNum, while the rest are dynamic.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:33:18+00:00Added an answer on June 14, 2026 at 7:33 pm

    Any structure that can grow as large as the user wants it to is going to be allocated on the heap. The memory stack, on the other hand, is used to allocate statically allocated variables, that the program has control of the size statically, during the compilation process.

    Since you can have a loop like this:

    for (i = 0; i < your_value; i++) {
        vector.insert(...);
    }
    

    And considering your_value as an integer read from the standard input, the compiler have no control on how large will be your vector, i.e., it does not know what is the maximum amount of inserts you may perform.

    To solve this, the structure must be allocated on the heap, where it may grow as large as the OS allows it to — considering primary memory, and swap. As a complement, if you use the pointer to the vector, you’ll be simply dynamically allocating a variable to reference the vector. This changes NOT the fact that the contents of the vector is, necessarily, being allocated on the heap.

    You’ll have, in your stack:

    • a variable “x” that stores the address of a variable “y”;

    And in your heap:

    • the value of the variable “y”, that is a reference to your vector of vectors;

    • the contents of your vector of vectors (accessed by “y”, that is accessed by “x”).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to initialize a vector of pairs with something like this std::vector< std::pair<bool,
I wanted to see if I could initialize a vector of objects in a
Being fairly new to iPhone / Objective-C development, I wanted to ask this question
I wanted to know after I initialize a combobox, is there a possibility that
So I have declared a vector in my class header like this: ... private:
Just as we can initialize vectors as: vector<int> var1(2000,1); Is it possible to initialize
I wanted to know that if I am doing correctly, regarding retain and release
I was trying to create a property which is readonly. I wanted to initialize
If I wanted to create a simple class that has three instance variables and
I wanted to make a generator that created files (and directories, etc...) based on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.