Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > vector is slow due to huge array

Reply
Thread Tools

vector is slow due to huge array

 
 
Nephi Immortal
Guest
Posts: n/a
 
      11-11-2011
I am going to create a huge array even as 100 MB. The problem is
that shift some elements in the right direction after number of
elements are inserted. Vector is slow due to shift issue. Linking
List is not the option because list of pointers take more memory.
I want to know how many elements are limited in order to use shift.
Perhaps, you recommend 4KB, 256KB, or 1 MB. The array of 100 MB is
divided into 4 KB pages or sub-arrays. The list of pointer gets each
page’s memory address.
The program can speed up and run faster if 4 KB pages are used. The
insert and shift can narrow to 4 KB page and leave other pages
untouched. It is an example of string object like word processor.
 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      11-11-2011
On Nov 11, 1:18*am, Nephi Immortal <immortalne...@gmail.com> wrote:

> * * * * I am going to create a huge array even as 100 MB. *The problem is
> that shift some elements in the right direction after number of
> elements are inserted. *Vector is slow due to shift issue.


yes. If you shift the first element you move 100M.

> *Linking
> List is not the option because list of pointers take more memory.
>
> * * * * I want to know how many elements are limited in order to use shift.


I think you need to measure. I'm guessing you've implemented this as a
list of vectors (or the moral equivalent). How big the vectors are
only you can answer. You're trading space against speed.
vector.size()==100M is too slow and vector.size()==1 is too big. Run
some tests, maybe on a smaller array. And decide what you find
acceptable.

> Perhaps, you recommend 4KB, 256KB, or 1 MB. *The array of 100 MB is
> divided into 4 KB pages or sub-arrays. *The list of pointer gets each
> page’s memory address.


4k sounds a good place to start then.

> * * * * The program can speed up and run faster if 4 KB pages areused. *The
> insert and shift can narrow to 4 KB page and leave other pages
> untouched. *It is an example of string object like word processor.


and is the size acceptable?

 
Reply With Quote
 
 
 
 
Arne Mertz
Guest
Posts: n/a
 
      11-11-2011
On Nov 11, 2:18*am, Nephi Immortal <immortalne...@gmail.com> wrote:
> * * * * I am going to create a huge array even as 100 MB. *The problem is
> that shift some elements in the right direction after number of
> elements are inserted. *Vector is slow due to shift issue. *Linking
> List is not the option because list of pointers take more memory.
> * * * * I want to know how many elements are limited in order to use shift.
> Perhaps, you recommend 4KB, 256KB, or 1 MB. *The array of 100 MB is
> divided into 4 KB pages or sub-arrays. *The list of pointer gets each
> page’s memory address.
> * * * * The program can speed up and run faster if 4 KB pages areused. *The
> insert and shift can narrow to 4 KB page and leave other pages
> untouched. *It is an example of string object like word processor.


What about using std::deque? Or, if your shifting/insertion has the
same amount
of elements each time, you could make up your own container wrapped
around something
like std::list<std::array<T, CHUNK_SIZE>>.

The size of your pages/chunks/subarrays should approximately match the
size of
a cache line on your system. Lower sizes would give you no performance
gain.
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      11-11-2011
On Fri, 2011-11-11, Nephi Immortal wrote:
> I am going to create a huge array even as 100 MB. The problem is
> that shift some elements in the right direction after number of
> elements are inserted. Vector is slow due to shift issue. Linking
> List is not the option because list of pointers take more memory.
> I want to know how many elements are limited in order to use shift.
> Perhaps, you recommend 4KB, 256KB, or 1 MB. The array of 100 MB is
> divided into 4 KB pages or sub-arrays. The list of pointer gets each
> page?s memory address.
> The program can speed up and run faster if 4 KB pages are used. The
> insert and shift can narrow to 4 KB page and leave other pages
> untouched. It is an example of string object like word processor.


About 20 years ago when I asked on Usenet about data structures for
text editing, I got the advice to use buffer-gap:

There seems to be a Wikipedia article; I don't know how good it is:
http://en.wikipedia.org/wiki/Gap_buffer

Also check out "The Craft of Text Editing" by Craig A. Finseth:
http://www.finseth.com/craft

It seems to me you need to do something like this; no standard
container would fit your problem.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory error due to the huge/huge input file size tejsupra@gmail.com Python 3 11-20-2008 07:21 PM
How to due with "warning LNK4075: ignoring '/INCREMENTAL' due to Fresh C++ 2 04-22-2008 09:03 PM
Initializing vector<vector<int> > and other vector questions... pmatos C++ 6 04-26-2007 05:39 PM
Free memory allocate by a STL vector, vector of vector, map of vector Allerdyce.John@gmail.com C++ 8 02-18-2006 12:48 AM
Uniform vector class, inheriting from Array: How to make sure thatmethods return a Vector and not an Array? Thomas Ruby 7 05-23-2005 04:21 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57