473,385 Members | 1,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

vector.resize() taking a short time on AMD, a long time on Intel

I really am not sure if this question belongs in this newsgroup, but not
sure where else to ask it.

There is someone working on a game that I tested, and it was taking >30
seconds to load. He stated that everyone else was taking 2 or 3 seconds.
Then he found one other person taking >30 seconds, and it turns out the
common denominator was both of us have Intel chips (Celeron) where the other
people have AMD.

I had him send me his code and he was doing a lot of .resize() in nested
vectors.

surfmap->IDR[surfindex].resize(bpgmap->width);for(y=0;ywidth;++y) {
surfmap->IDR[surfindex][y].resize(bpgmap->height+2); }
surfmap->IDG[surfindex].resize(bpgmap->width);for(y=0;ywidth;++y) {
surfmap->IDG[surfindex][y].resize(bpgmap->height+2); }
surfmap->IDB[surfindex].resize(bpgmap->width);for(y=0;ywidth;++y) {
surfmap->IDB[surfindex][y].resize(bpgmap->height+2); }
surfmap->IDA[surfindex].resize(bpgmap->width);for(y=0;ywidth;++y) {
surfmap->IDA[surfindex][y].resize(bpgmap->height+2); }

I looked at this and had him display clock() times before and after, and
sometimes this block of code would take >200ms on our Intel chips, but
ususually ~30ms on AMD.

I wrote a class for him that allocated the block of memory with one call to
new and gave him accessors which he replaced this with and now clock is
reporting 0 ms on AMD (haven't tested it on Intel yet).

My question is, why would the .resize() take so much longer on Intel than
AMD? Is it something specific to the Celeron maybe?

Before I rewrote it as a class for him I had considered things such as
..clear() .reserve() but that didn't immediately update the .size() for the
vector, and I think the class is the best way to go after all.
May 31 '06 #1
3 2452
Jim Langston wrote:
I really am not sure if this question belongs in this newsgroup, but not
sure where else to ask it.

There is someone working on a game that I tested, and it was taking >30
seconds to load. He stated that everyone else was taking 2 or 3 seconds.
Then he found one other person taking >30 seconds, and it turns out the
common denominator was both of us have Intel chips (Celeron) where the other
people have AMD.

I had him send me his code and he was doing a lot of .resize() in nested
vectors.
Have a look at the code generated for the constructors of whatever is in
the vector, resize defaults to the object's default constructor to
initialise the new elements.

Before I rewrote it as a class for him I had considered things such as
..clear() .reserve() but that didn't immediately update the .size() for the
vector, and I think the class is the best way to go after all.

reserve doesn't initialise the vector's elements, unlike resize which does.

--
Ian Collins.
May 31 '06 #2
"Ian Collins" <ia******@hotmail.com> wrote in message
news:4e*************@individual.net...
Jim Langston wrote:
I really am not sure if this question belongs in this newsgroup, but not
sure where else to ask it.

There is someone working on a game that I tested, and it was taking >30
seconds to load. He stated that everyone else was taking 2 or 3 seconds.
Then he found one other person taking >30 seconds, and it turns out the
common denominator was both of us have Intel chips (Celeron) where the
other
people have AMD.

I had him send me his code and he was doing a lot of .resize() in nested
vectors.

Have a look at the code generated for the constructors of whatever is in
the vector, resize defaults to the object's default constructor to
initialise the new elements.

Before I rewrote it as a class for him I had considered things such as
..clear() .reserve() but that didn't immediately update the .size() for
the
vector, and I think the class is the best way to go after all.

reserve doesn't initialise the vector's elements, unlike resize which
does.


Yes, this I know, but right after he did the resize he was iterating through
all the vectors initializing them anyway. But the issue of the .size() not
being right caused problems such as this:

std::vector<int> MyVec;
MyVec.reserve(100);
MyVec[50] = 10;

This worked on my compiler with my settings but barfed on his machine
stating that it was an array overflow.
May 31 '06 #3
Jim Langston wrote:
"Ian Collins" <ia******@hotmail.com> wrote in message
news:4e*************@individual.net...

reserve doesn't initialise the vector's elements, unlike resize which
does.

Yes, this I know, but right after he did the resize he was iterating through
all the vectors initializing them anyway. But the issue of the .size() not
being right caused problems such as this:

std::vector<int> MyVec;
MyVec.reserve(100);
MyVec[50] = 10;

This worked on my compiler with my settings but barfed on his machine
stating that it was an array overflow.

It probably should barf, reserve simply reserves memory, it doesn't
initialise anything else. size() will be unchanged, capacity() will
reflect the new allocation.

--
Ian Collins.
May 31 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jessica | last post by:
Hi, I do not have a lot of experience with STL and I hope some of you might be able to help me on this seemingly elementary question. I have a vector of doubles (v1). I am trying to copy the...
9
by: luigi | last post by:
Hi, I am trying to speed up the perfomance of stl vector by allocating/deallocating blocks of memory manually. one version of the code crashes when I try to free the memory. The other version...
8
by: Jason Heyes | last post by:
Does the STL have a function like this one? template <typename T> void remove(std::vector<T> &v, std::vector<T>::size_type index) { std::swap(v, v.back()); v.resize(index); } Unlike...
9
by: Gernot Frisch | last post by:
Hi, I want to be able to write: class foo { std::vector<intm_i (64); }
14
by: markww | last post by:
Hi, I want to use the vector container class to store pixel data. Currently I have some memory allocated using c++'s new operator. I allocate the memory differently based on if the pixel type is...
12
by: mast2as | last post by:
Hi everyone I am working on some code that uses colors. Until recently this code used colors represented a tree floats (RGB format) but recently changed so colors are now defined as spectrum....
10
by: StephQ | last post by:
I found that old post: http://groups.google.com/group/comp.lang.c++/browse_frm/thread/3a2562c9a5f8998/15519204726d01e8?lnk=gst&q=vector+no+surprise&rnum=2#15519204726d01e8 I just erased the...
9
by: xman | last post by:
The codes below basically builds a binary tree. It runs well on Intel compiler. However, when I use gcc 4.2.0, the assignment to b.right causes segmentation fault. Tracing with valgrind reveals...
19
by: Daniel Pitts | last post by:
I have std::vector<Base *bases; I'd like to do something like: std::for_each(bases.begin(), bases.end(), operator delete); Is it possible without writing an adapter? Is there a better way? Is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.