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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:46:03+00:00 2026-06-10T06:46:03+00:00

I have a question on memory allocation for containers on C++. Look at the

  • 0

I have a question on memory allocation for containers on C++.

Look at the pseudocode for a multi threaded application (assume it is in c++). I declare vector object in the main method. Then I run a thread and pass this object to the thread. The thread runs in another processor. Now, I insert 100000 elements into the vector.

typedef struct myType
{
    int a;
    int b;
}myType;

ThreadRoutine()
{
    Run Thread in processor P;
    insert 1000000 elements into myTypeObject
}

int main()
{
    std::vector<myType> myTypeObject;
    CALLTHREAD and pass myTypeObject
} 

I want to know where the memory will be allocated for the 100000 elements:
-From the main itself
-From the thread

The reason I ask this is because, I want to run the thread in a different processor. And my machine is a NUMA machine. So if the memory is allocated from the thread, it will be in the local memory bank of the thread. But if the memory is allocated from main, it will be allocated from the local memory bank of the main thread.

By my intuition, I would say that the memory is allocated only in the threads. Please let me know your thoughts.

  • 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-10T06:46:04+00:00Added an answer on June 10, 2026 at 6:46 am

    the reallocation(s) will be called from ThreadRoutine() — so, whichever thread calls that (the secondary in your example).

    of course, you could reserve on the main thread before passing it around, if you want to avoid resizing on the secondary thread.

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

Sidebar

Related Questions

I have this question regarding memory allocation and deallocation in c++. Here is the
I have a question regarding memory allocation order. In the following code I allocate
I have a multiple choice question about memory allocation C, but I'm sure which
I'm developing an iPhone app and have a question about memory management. Let's say
I have a question about structure padding and memory alignment optimizations regarding structures in
hello I have a small question in objective-C memory management. I know that if
I have an other active question HERE regarding some hopeless memory issues that possibly
A different question inspired the following thought: Does std::vector<T> have to move all the
I have a question about variable scope and memory management in C. I am
I have a question regarding some memory management in C. I have to allocate

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.