The Artima Developer Community
Sponsored Link

Weblogs Forum
The Positive Legacy of C++ and Java

210 replies on 15 pages. Most recent reply: May 8, 2009 11:50 PM by Daesung Park

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 210 replies on 15 pages [ « | 1 ... 3 4 5 6 7 8 9 10 11 ... 15  | » ]
John Wellbelove

Posts: 72
Nickname: garibaldi
Registered: Mar, 2008

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 4:49 AM
Reply to this message Reply
Advertisement
> Whereas in my work (graph algorithms, vehicle routing,
> computational geometry), if I was using C++ they would be
> routine and unavoidable.
Are you using STL and/or Boost at all?

Mark Thornton

Posts: 275
Nickname: mthornton
Registered: Oct, 2005

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 4:59 AM
Reply to this message Reply
> > Whereas in my work (graph algorithms, vehicle routing,
> > computational geometry), if I was using C++ they would
> be
> > routine and unavoidable.
> Are you using STL and/or Boost at all?

I don't use C++ any more, so no. However the data structures that are the core of my work necessarily include cycles and thus need either garbage collection or explicit new/delete. An acyclic road network would not be of much use.

Nemanja Trifunovic

Posts: 172
Nickname: ntrif
Registered: Jun, 2004

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 5:00 AM
Reply to this message Reply
>
> Send in your GenerateSomeRandomString method (by the way,
> in Java, methods start with lower case by convention, and
> one should avoid endless loops, not good practice in
> general), and maybe we can help find your memory leak ;)
>

:)

I don't have the method, and I don't assume it leaks. In fact, I wrote something similar in C# some 5 years ago just to confirm that the high memory usage was not a consequence of a bug in the application code.

Off topic, don't you find at least a bit ironic to see a Java programmer offering a C++ programmer help in finding a memory leak :)

Nemanja Trifunovic

Posts: 172
Nickname: ntrif
Registered: Jun, 2004

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 5:04 AM
Reply to this message Reply
> init=0
> used=439552
> committed=5177344
> max=66650112
>
> used=988008
> committed=5177344
>
> used=241416
> committed=5177344
>
> etc
> The committed memory did not increase. The used memory
> oscillated up and down in the range 180K up to about 1M.

But that's exactly what I am talking about! Do you think it is normal to have all these memory commited when you are using just one string at the time?

Did you try looking for page faults?

Mark Thornton

Posts: 275
Nickname: mthornton
Registered: Oct, 2005

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 5:05 AM
Reply to this message Reply
> I don't have the method, and I don't assume it leaks. In
> fact, I wrote something similar in C# some 5 years ago
> just to confirm that the high memory usage was not a
> consequence of a bug in the application code.

Did it occur to you that it might have been a bug or poor implementation in .NET and not a generic problem with garbage collection?

Mark Thornton

Posts: 275
Nickname: mthornton
Registered: Oct, 2005

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 5:17 AM
Reply to this message Reply
>
> But that's exactly what I am talking about! Do you think
> it is normal to have all these memory commited when you
> are using just one string at the time?

The committed size just reflects the default value of the minimum heap size parameter. I could have overriden that, but there is usually little point unless your machine is unusually memory constrained.

> Did you try looking for page faults?
Page faults in themselves are not a very useful measure on Windows (I was using Vista for this test). The relevant aspect is that running this test placed no memory strain on my system at all.

John Wellbelove

Posts: 72
Nickname: garibaldi
Registered: Mar, 2008

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 5:41 AM
Reply to this message Reply
> I don't use C++ any more, so no. However the data
> structures that are the core of my work necessarily
> include cycles and thus need either garbage collection or
> explicit new/delete. An acyclic road network would not be
> of much use.

http://www.boost.org/doc/libs/1_38_0/libs/graph/doc/index.html

Mark Thornton

Posts: 275
Nickname: mthornton
Registered: Oct, 2005

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 6:16 AM
Reply to this message Reply
>
> http://www.boost.org/doc/libs/1_38_0/libs/graph/doc/index.h
> tml

Quite nice. It didn't exist when I was last using C++ for this sort of work. I would also observe that someone has to write the libraries and algorithms, something I have been doing for over 25 years.
I do use a similar 3rd party Java library for some purposes, but it doesn't always suit.

Nemanja Trifunovic

Posts: 172
Nickname: ntrif
Registered: Jun, 2004

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 6:28 AM
Reply to this message Reply
>
> > Did you try looking for page faults?
> Page faults in themselves are not a very useful measure on
> Windows (I was using Vista for this test). The relevant
> aspect is that running this test placed no memory strain
> on my system at all.

I am not sure what you mean by "memory strain" if you don't find page faults relevant. What is relevant then? Page faults (especially hard page faults) are the main reason that high memory consumption affects performance.

Nemanja Trifunovic

Posts: 172
Nickname: ntrif
Registered: Jun, 2004

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 6:30 AM
Reply to this message Reply
> In
> > fact, I wrote something similar in C# some 5 years ago
> > just to confirm that the high memory usage was not a
> > consequence of a bug in the application code.
>
> Did it occur to you that it might have been a bug or poor
> implementation in .NET and not a generic problem with
> garbage collection?

I see the same problem in the results of your test, therefore I don't think it is specific to .NET.

Cameron Purdy

Posts: 186
Nickname: cpurdy
Registered: Dec, 2004

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 6:48 AM
Reply to this message Reply
> Dare I say that C++ programmers who took to Java with such
> enthusiasm were maybe not writing that good C++ in the
> first place. Their inappropriate or overuse of manual
> memory allocation in C++ was translated into normal syntax
> in Java.

I am reminded of the Dilbert where Alice is getting her review from the Pointy-Haired Boss:

Pointy-Haired Boss: "Your biggest defect continues to be your inability to handle criticism."
Alice (thinks to self): "I can't argue with his stupid misperception without proving it true."
Pointy-Haired Boss: "And you argue with people who are much smarter than yourself."
Alice (unable to hold it in): "GAAA!!!"

At any rate, I asked the questions that I did because I see fewer and fewer problem domains that are adequately addressed by lower-level languages than Java/C# etc. By lower-level, I mean languages that are old enough to not provide facilities that are commonly expected today, such as garbage collection, intrinsic support for thread safety and concurrent programming, a well-integrated run-time type system, an exhaustive standard class library, etc.

So I have a different question for you, since you brought up the supposition that people fled to Java because it was too hard for them to "write good C++ in the first place" .. do you think it is naturally more difficult to write good C++, and do you think that is a good characteristic or something to be avoided in a language? ;-)

Peace,

Cameron.
http://www.oracle.com/technology/products/coherence/index.html

Mark Thornton

Posts: 275
Nickname: mthornton
Registered: Oct, 2005

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 6:50 AM
Reply to this message Reply
> Page faults (especially hard page faults) are the main
> reason that high memory consumption affects performance.

Hard page faults matter, the others don't matter at all. The 'soft' page faults are just part of assessing the appropriate working set for your process. In effect they an artifact of the Windows virtual memory management algorithm.

What you really want to know is a combination of the working set size and the hard page fault rate. Together this gives an idea of how much memory the process really needs.

What happens in this test case is that Java is actively using about 1MB of heap. Each String is allocated by simply incrementing pointers until the space is full, then the live data is copied (very little in this case). Using a relatively large area for this initial allocation allows the collection to occur less frequently. It also permits the reclaimed space to be initialised to zero in bulk.

In a real application the ratio between the live data and heap size would be less extreme (Sun's Java 1.6U10 implementation doesn't permit a heap of less than 2MB). Sure if you really need to run within a heap/data size of less than 100K or so, then GC languages may not be appropriate, but implementations for constrained environments do exist.

Nemanja Trifunovic

Posts: 172
Nickname: ntrif
Registered: Jun, 2004

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 8:08 AM
Reply to this message Reply
>
> What happens in this test case is that Java is actively
> using about 1MB of heap. Each String is allocated by
> simply incrementing pointers until the space is full, then
> the live data is copied (very little in this case). Using
> a relatively large area for this initial allocation allows
> the collection to occur less frequently. It also permits
> the reclaimed space to be initialised to zero in bulk.

What I am saying here is that a non-deterministic GC unavoidably leads to higher memory consumption. While in this one-string-at-the-time sample it does not cause visible performance issues, in a more real-life scenario it often does.

In fact, there is a nice (pro-GC) article on lambda the ultimate that proposes a GC-aware virtual memory manager as a solution to performance problems caused by non-deterministic garbage collection. It can be found here: http://lambda-the-ultimate.org/node/2391

"Garbage collection offers numerous software engineering advantages, but interacts poorly with virtual memory managers. Existing garbage collectors require far more pages than the application’s working set and touch pages without regard to which ones are in memory, especially during full-heap garbage collection."

John Wellbelove

Posts: 72
Nickname: garibaldi
Registered: Mar, 2008

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 8:12 AM
Reply to this message Reply
> .. do you think it is naturally more difficult to write
> good C++, and do you think that is a good characteristic
> or something to be avoided in a language? ;-)

No, I don't think it is difficult to write good C++ especially with STL & Boost. The bad use comes from treating C++ as 'C with classes' and continuing to use old C idioms.
I've been using 'modern' C++ for some time and I find a lot of the criticisms aimed at the language just have no bearing on the code I write today.

Mark Thornton

Posts: 275
Nickname: mthornton
Registered: Oct, 2005

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 8:16 AM
Reply to this message Reply
> What I am saying here is that a non-deterministic GC
> unavoidably leads to higher memory consumption.
True, but in most applications the extra usage is not sufficient to matter, and there compensating advantages.

> "Garbage collection offers numerous software engineering
> advantages, but interacts poorly with virtual memory
> managers. Existing garbage collectors require far more
> pages than the application’s working set and touch pages
> without regard to which ones are in memory, especially
> during full-heap garbage collection."
Although this can indeed be a problem, the impact can be reduced with garbage collectors that do a full gc cycle far less frequently than was required in the past. The test example didn't do any full heap collections at all despite allocating many GB worth of String's. A better virtual memory manager would be nice, but for now the answer is to know your garbage collectors.

Flat View: This topic has 210 replies on 15 pages [ « | 3  4  5  6  7  8  9  10  11 | » ]
Topic: Should I use a netbook as my main development platform? Previous Topic   Next Topic Topic: Social Newsfeeds: The Next Big Thing

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use