Thread: vector::insert is so slow

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    932

    vector::insert is so slow

    I opened up a large file of 700MB and read it in a vector<char> and then I want to insert in front of the file its size.
    I turns out to be not only very slow but also max out the CPU.
    Is it normal or am I doing something wrong?
    It works well on smaller files though.

    Code:
        char szDigits[32] = "700111222";
        vector<char> v(filesize+260, '0'); // contains file 
    
        for(int i = 0; i< 9; i++)  // it gets very slow here
        {
            v.insert(v.begin()+i, szDigits[i]);
            cout << "i: " << i << endl;
        }
    Last edited by Ducky; 06-15-2013 at 08:02 AM.
    Using Windows 10 with Code Blocks and MingW.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-27-2011, 05:31 AM
  2. Insert new element into a vector
    By appointment in forum C++ Programming
    Replies: 7
    Last Post: 08-16-2009, 01:54 AM
  3. vector<...>::iterators and insert - I'm stumped.
    By Dino in forum C++ Programming
    Replies: 6
    Last Post: 12-25-2007, 06:11 AM
  4. vector insert functions
    By kes103 in forum C++ Programming
    Replies: 4
    Last Post: 03-24-2003, 03:12 PM
  5. Replies: 1
    Last Post: 09-17-2001, 05:46 AM