Linked by Eugenia Loli-Queru on Tue 8th Nov 2005 07:55 UTC, submitted by I_Use_Tooooo_Many_Names
General Development Modern memory management isn't as simple as knowing that you have 150MB of programs to run and 256MB of memory to do it in. Modern Unix-like operating systems have their own characteristics for allocating and using memory. Howard Feldman explains how this works and shows how to analyze and reduce the memory consumption of your programs, no matter what language you use.
Thread beginning with comment 57804
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE[4]: Hum...
by BryanFeeney on Tue 8th Nov 2005 14:38 UTC in reply to "RE[3]: Hum..."
BryanFeeney
Member since:
2005-07-06

I learned C++ about seven years ago, when smart pointers weren't well known; these days I mainly use Java, Delphi plus one other scripting language (currently hovering between PHP and Perl, though I'd love to look at Ruby if I get the chance).

I've avoided C++ for the most part, I think it's an awful jumble of a language (you know you've got problems when you have four casting methods to choose from). As a result I've never used smart pointers. I will say, though, that a C++ programmer still needs to be acutely aware of how memory works to ensure their application doesn't leak anything: using auto_ptr<> with lists of objects shared across the application, for example, can result in nasty surprises, e.g.

void crazyFunc()
{
auto_ptr<MyClass*> mc = new MyClass();
auto_ptr<MyList*> list = myOtherClass->MyList;
list->add (mc);
}

void crashInBurnBaby()
{
auto_ptr<MyList*> list = myOtherClass->MyList;
cout << dynamic_cast<MyClass*> (list[0])->attr;
}

The obvious solution is to have a good hard look at the smart pointers available to you (e.g. http://www.boost.org/libs/smart_ptr/smart_ptr.htm), or else use normal pointers or references in certain areas, but at that rather complex point, aren't you - the developer - working quite hard to avoid leaking memory?

Reply Parent Bookmark Score: 1

RE[5]: Hum...
by cloose on Tue 8th Nov 2005 16:35 in reply to "RE[4]: Hum..."
cloose Member since:
2005-07-12

You should of course *not* use std::auto_ptr<> for lists. That's what the STL containers like std::vector or std::list are for.

IMO you shouldn't judge a programming language when you haven't really used it lately. It's like judging Java based on experiences with Java 1.0.

Reply Parent Bookmark Score: 2

Problems with the link
by on Tue 8th Nov 2005 16:50 in reply to "RE[5]: Hum..."
Member since:

Is it just me or is there a conflict between the linked web site and Firefox?

On my Ubuntu Breezy system, after a minute or so, my browser's shared memory is 125 MB and its CPU use at 96%, untill it finally crashes.

I am using the latest 1.5 RC1. I have also tried the earlier 1.7 (not the Ubuntu version).

Reply Parent Bookmark Score: 0