Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: Do you use a garbage collector (java vs c++ difference in "new")

Reply
Thread Tools

Re: Do you use a garbage collector (java vs c++ difference in "new")

 
 
Ian Collins
Guest
Posts: n/a
 
      04-11-2008
Razii wrote:
> On Thu, 10 Apr 2008 19:14:12 -0500, Razii
> <> wrote:
>
>>> However, part of my C++ programming style just naturally also avoids
>>> doing tons of news and deletes in tight loops (which is, again, very
>>> different from eg. Java programming where you basically have no choice)

>
> Let's test this about the keyword "new" and tight loops. Because in
> most cases Java allocates new memory blocks on it's internal heap and
> bypasses memory allocation mechanisms of the underlying OS, the
> keyword "new" doesn't mean the same thing that it does in C++, where
> each "new" allocation request is sent to the operating system, which
> is very slow.
>
> Creating 10000000 new objects with the keyword 'new' in tight loop.
>

If a C++ programmer had to do this in the most efficient way possible,
he/she would use a custom allocator.

> int main(int argc, char *argv[]) {
>
> clock_t start=clock();
> for (int i=0; i<=10000000; i++) {
> Test *test = new Test(i);
> if (i % 5000000 == 0)
> cout << test;
> }


Leaks 10000000 objects.

>
> for (int i=0; i<=10000000; i++) {
> Test test = new Test(i);
> if (i % 5000000 == 0)
> System.out.println (test);
> }


Does the Java allocator/GC combination recycle the objects in the loop?

--
Ian Collins.
 
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
Re: Do you use a garbage collector (java vs c++ difference in "new") Roedy Green Java 14 04-14-2008 03:37 PM
Re: Do you use a garbage collector (java vs c++ difference in "new") Juha Nieminen Java 10 04-13-2008 08:35 PM
Re: Do you use a garbage collector (java vs c++ difference in "new") Arne Vajhøj Java 12 04-13-2008 12:13 AM
Re: Do you use a garbage collector (java vs c++ difference in "new") asterisc Java 6 04-12-2008 12:09 AM
Re: Do you use a garbage collector (java vs c++ difference in "new") Ian Collins Java 2 04-11-2008 09:24 AM



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