By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

Becoming familiar with memory management

P: n/a
Basically i am a student taking an operating systems course which
is c++ intensive. Familiar with Java, and so not so familiar with memory
management. Looking for suggestions of exercises or web resources to help
me become familiar with pointers and referencing etc. Thank you.

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
DANIEL BEAULIEU J wrote:
Basically i am a student taking an operating systems course which
is c++ intensive. Familiar with Java, and so not so familiar with memory
management. Looking for suggestions of exercises or web resources to help
me become familiar with pointers and referencing etc. Thank you.


In C++, the dynamic memory management is through
the "new" and "delete" operators or via the functions
"malloc" and "free". Don't mix the pairs.

Read the FAQs and Welcome.txt below for more information.
There is also book recommendations in there as well.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Jul 23 '05 #2

P: n/a
Thomas Matthews wrote:
DANIEL BEAULIEU J wrote:
Basically i am a student taking an operating systems course which
is c++ intensive. Familiar with Java, and so not so familiar with
memory management. Looking for suggestions of exercises or web
resources to help me become familiar with pointers and referencing
etc. Thank you.


In C++, the dynamic memory management is through
the "new" and "delete" operators or via the functions
"malloc" and "free". Don't mix the pairs.

Read the FAQs and Welcome.txt below for more information.
There is also book recommendations in there as well.


In particular, once you get the general idea of new and delete (or
malloc and free), you might want to have a look at so-called "Smart
Pointers". They are an idiomatic approach to memory management with C++,
and take a lot of the burden of managing memory in C++ (in particular,
this approach is essential in the presence of C++ exceptions).

Smart pointers solve the problem of memory leaks (i.e. allocating memory
(with "new") but not deallocating it (with "delete")) by encapsulating
the new and delete in their constructor and destructor, respectively.
The language guarantees that an object's destructor is always executed,
hence the delete is guaranteed to be executed.

The aforementioned FAQ (http://www.parashift.com/c++-faq-lite) shows
such an approach in 16.21.

Other than that, these handle objects provide the same interface as
pointers (the dereference operator etc.), hence the name smart pointers.

Other keywords to google for in this regard are "handle-body idiom"
(e.g. http://www.cs.vu.nl/~dejavu/context/node2.html) and "resource
acquisition is initialization" (RAII) (see part 8 of Stephen Dewhurst's
article "C++ Memory and Resource Management" at
http://www.informit.com/articles/art...0642&seqNum=8), or just
"C++ memory management".

Kind regards,
Andreas
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.