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

  • SEARCH
  • Home
  • 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 9160541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:45:49+00:00 2026-06-17T13:45:49+00:00

I am interested in at least an approximate answer to: int n; … std::vector<void*>

  • 0

I am interested in at least an approximate answer to:

int n;
...
std::vector<void*> vectorOfPointers;
vectorOfPointers.reserve(n);

For up to which number n does the above mentioned program run in O(1) ?

Let us suppose that for a laptop running 32 bit Ubuntu with 3 gigabytes of memory, not running any other programs. Is it tens, thousands, millions? What information does one need to know to be able to asses such a question? Is there a way to find out without running any experiments?

I have never studied anything about operating systems but in my imagination, the operating system allocates memory in just 2 steps. It determines the pointer to start the chunk and the pointer of the end of the chunk. The situation can be more complicated because the system may have to tidy up in order to get a big enough chunk of memory. But if we suppose that the system runs just this one program, how can we estimate the time needed? Are there some other aspects to be considered, besides the fragmentation of memory?

EDIT:

sorry, I didn’t make my question clear. It is important to consider, that the vector is empty before calling reserve, so no copying of data is required.

  • 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-17T13:45:51+00:00Added an answer on June 17, 2026 at 1:45 pm

    From the C++ point of view, the code takes O(1) time (it’s linear in the current size of the container, which in your case is always zero).

    Now, it seems that your question is really about the complexity of allocating m bytes of memory. That, I am afraid, is unspecified.

    For further discussion, see Time complexity of memory allocation

    To add to what’s already been said in the other question, there are several layers of complexity:

    • Firstly, malloc() needs to maintain its internal data structures. The complexity of doing that is not specified, but one would hope that malloc(m) would not take Θ(m) time. However, the complexity could well depend on other factors, such as memory fragmentation.
    • Secondly, malloc() may need to request additional memory from the OS. Here, it is not unreasonable to expect the OS to do something with every memory page it allocates (e.g. wipe it so you don’t see someone else’s confidential data). If this were to happen, the operation would indeed be Θ(m).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm interested in building an uninitialized_vector container, which will be semantically identical to std::vector
I am very interested in at least trying to implement NAT break through for
I hava a char variable, and i am only interested in the two least
I'm interested to find a library for NLP/text processing purposes which presents a common
Given a cubic polynomial estimated using least-squares regression, I am interested in a simple
I have a custom CLI debugger for which I'm interested in a GUI. The
I'm interested in opinions on design. There are at least two ways to locate
I'm interested what's the average line number per method or class . Programming language
I'm interested in articles which have some concrete information about stateless and stateful design
I'm not a math guy in the least but I'm interested in learning about

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.