Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Juha Nieminen Newsgroups: comp.lang.c++,comp.programming.threads Subject: Re: Why is java consumer/producer so much faster than C++ Date: Mon, 23 Jul 2012 11:46:37 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 30 Message-ID: References: NNTP-Posting-Host: x6oKauqjz/aVLymSbCEcrg.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org User-Agent: tin/1.9.6-20100522 ("Lochruan") (UNIX) (Linux/3.1.10-grbfs-kapsi (x86_64)) X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.c++:17197 comp.programming.threads:968 In comp.lang.c++ Melzzzzz wrote: > I think that pressure on condition variable is greater with non > dynamic allocation, therefore it is slower. That sentence doesn't make any kind of sense. > I don't think it's >> physically possible for 'new int' to be faster than using ints by >> value under any possible circumstance, even if we assumed a highly >> optimized version of 'new' that does magic under the hood to be 10 >> times faster than the regular 'new'. > > That's because new is very fast and don;t take much time of program > in this example. 'new' is a very slow operation in C++, and even if it weren't, it just can't be faster than using an integer by value. It's physically impossible. (The pointer that points to the allocated int is also an integral value at the low level, so by allocating something dynamically you are only adding to the amount of values being handled, and the overall complexity of the program.) Can you give any scenario where handling pointers would be faster than handling ints? >> 'new' is slow, especially when compared to java's. > > In this example new takes very little time. You are executing tens of thousands of 'new's. That is slow.