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 8850017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:48:05+00:00 2026-06-14T12:48:05+00:00

I ran into a funny issue today working with large data structures. I initially

  • 0

I ran into a funny issue today working with large data structures. I initially was using a vector to store upwards of 1000000 ints but later decided I didn’t actually need the dynamic functionality of the vector (I was reserving 1000000 spots as soon as it was declared anyway) and it would be beneficial to, instead, be able to add values any place in the data structure. So I switched it to an array and BAM stack overflow. I’m guessing this is because declaring the size of the array at compile time puts it in the stack and making use of a dynamic vector instead placed it on the heap (which I’m guessing is larger?).

So what’s the right answer here? Move back to a dynamic memory system just so it gets put on the heap? Increase the size of the stack? Or am I way off base on the whole thing here…?

Thanks!

  • 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-14T12:48:07+00:00Added an answer on June 14, 2026 at 12:48 pm

    I initially was using a vector to store upwards of 1000000 ints

    Good idea.

    but later decided I didn’t actually need the dynamic functionality of the vector (I was reserving 1000000 spots as soon as it was declared anyway)

    Not such a good idea. You did need it.

    and it would be beneficial to, instead, be able to add values any place in the data structure.

    I don’t follow.

    I’m guessing this is because declaring the size of the array at compile time puts it in the stack and making use of a dynamic vector instead placed it on the heap (which I’m guessing is larger?).

    Much. The call stack is typically of the order of 1MB-2MB in size by default. Your “heap” (free store) is only really bounded by your available RAM.

    So what’s the right answer here? Move back to a dynamic memory system just so it gets put on the heap?

    Yes.

    [edit: Joachim’s right — static is another possible answer.]

    Increase the size of the stack?

    You could but even if you could stretch 4MB out of it, you’ve left yourself no wiggle room for other local data variables. Best use dynamic memory — that’s the appropriate thing to do.

    Or am I way off base on the whole thing here…?

    No.

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

Sidebar

Related Questions

I ran into an issue today because I am developing an application in Visual
Ran into a issue today. abc.ClassA a = (abc.ClassA) request.getsession().getAttribute(); and i get classcast
Ran into an issue today that I have not been able to resolve. I
Ran into this problem today, posting in case someone else has the same issue.
I ran into an interesting (and very frustrating) issue with the equals() method today
I ran into a strange issue while using JPA (with EclipseLink 4.2.1). The relevant
I ran into a problem using Springsource Tool Suite when writing some groovy scripts
I ran into a strange issue with tinyMCE that i was not able to
Ran into a strange problem in PHP today and I'm wondering if someone can
I have the funny situation, that I store a Coordinate into a HashMap<Coordinate, GUIGameField>

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.