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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:59:29+00:00 2026-06-08T16:59:29+00:00

Is there a well-known solution to the following problem? You have a vector of

  • 0

Is there a well-known solution to the following problem?

  • You have a vector of a lot of strings

  • You happily populate it with a few hundred thousand strings, and it’s fast

  • You manipulate your strings in arbitrary ways; life is good.

  • You’re done with the vector; vector goes out of scope, and now you have to go grab some coffee and sit back while each string gets destroyed one-by-one.

Edit: Problem solved!

I just ran the code below on Linux on the same computer and it was fine, which led me to figure out the solution. It turned out to be with my system — something I’d caused myself, a long time ago, but which I’d forgotten.
Upon fixing the problem, the time decreased dramatically, to even better than with GCC!

It’s a good puzzle though, so instead of posting the answer, I’ll do something else:
I’m not allowed to place a bounty on this question right now, but if you think you know the cause, give it a shot. If it’s correct, I’ll accept it and give you a nice bounty. (Remind me if I forget to give you the bounty!)
If no one knows then I’ll just post it myself after some time passes.

Sample code:

I used to be as skeptical as anybody, but now I guess people do have a point when they the STL is slow!
This took 3.95 seconds on my laptop: (the shuffling is critical)

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <string>
#include <vector>

int main()
{
    using namespace std;
    srand((unsigned)time(NULL));
    clock_t start;
    {
        vector<string> v(400000);
        for (size_t i = 0; i < v.size(); i++)
        {
            v[i].resize(16 + rand() % 32);  // some variation
        }

        // shuffle
        for (size_t i = 0; i < (size_t)pow((double)v.size(), 1.15); i++)
        {
            size_t j = rand() * (RAND_MAX + 1) + rand();
            swap(v[i % v.size()], v[j % v.size()]);
        }
        
        printf("Going out of scope...\n"); fflush(stdout);
        start = clock();
    }
    clock_t end = clock();
    printf("%u ms\n", (end - start) * 1000 / CLOCKS_PER_SEC);
    return 0;
}

It looks to me like this program is using some O(n2) algorithm internally, either in Visual C++ or in Windows. Not sure what’s happening, but it’s interesting…

  • 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-08T16:59:31+00:00Added an answer on June 8, 2026 at 4:59 pm

    Okay, since nobody figured it out…

    It was because heap tail checking was turned on in my system. Once I removed it, the code finished quickly.

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

Sidebar

Related Questions

Is there any well-known algorithm (or obvious solution) for transforming a list from order
I have a problem with magic method __call The following code works well, except
For each of the modern browsers are there well known hooks I can tie
There are well-known algorithms for cryptography to compute modular exponentiation (a^b)%c (like Right-to-left binary
Is there a well-known, portable, good library for C++ process management? I found a
There is a well known issue when it comes to using .NET value types
It seems to be well-known there is a bug when using JMenuItem.getRootPane(). I read
Simplified, I have to solve the following problem: You have a 2-dimensional array filled
I have the very well-known WinAPI function: BOOL WINAPI RegisterHotKey( __in_opt HWND hWnd, __in
It is a well known problem to every web developer. As far as I

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.