Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > I'm Shocked

Reply
Thread Tools

I'm Shocked

 
 
Old Wolf
Guest
Posts: n/a
 
      03-04-2007
On Mar 3, 11:24 pm, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
> Bas wrote:
> >
> > Test *ar[30000000];
> > for(long int j = 0; j< 30000000; j++)
> > ar[j] = new Test;

>
> std::vector<Test> v( 30000000 );


The thing being benchmarked was 30000000 small allocations.
Your suggested code performs 1 large allocation.

(I'm sure you know this; but just clearing it up for other readers who
may not).

 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      03-04-2007
* Old Wolf:
> On Mar 3, 11:24 pm, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
>> Bas wrote:
>>> Test *ar[30000000];
>>> for(long int j = 0; j< 30000000; j++)
>>> ar[j] = new Test;

>> std::vector<Test> v( 30000000 );

>
> The thing being benchmarked was 30000000 small allocations.
> Your suggested code performs 1 large allocation.
>
> (I'm sure you know this; but just clearing it up for other readers who
> may not).


Yes. The point is that for a an ordinary C# 'class' object (reference
semantics) you have to do those 30M separate allocations to have the 30M
objects you need, whatever the reason could be for that need, whereas in
C++ you can do just one big allocation. So as a /language/ comparision
this one decidedly favors C++, some millions times faster than C#.

I think if the comparision is meaningful in any way, then that way must
be it.

Cheers,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
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
a different type of reference (shocked) SpringFlowers AutumnMoon Ruby 18 10-02-2007 05:05 PM
I'm shocked -- SHOCKED !! George Orwell DVD Video 35 04-19-2007 12:37 AM
ICANN members shocked at NZ fraudband Philip NZ Computing 12 03-28-2006 09:32 AM
my friend claims a faulty CRT shocked him in the nads Lucas Tam Digital Photography 34 03-21-2005 12:44 PM



Advertisments