473,387 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Becoming familiar with memory management

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
2 1934
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Richard Jones | last post by:
Garbage Collection & Memory Management Summer School 20-21 July 2004, Canterbury, UK The performance of today's memory-hungry applications depends on efficient dynamic memory management,...
9
by: Mike P | last post by:
I know everything about reference counting and making sure you don't have large objects lying around. I have also profiled my app with multiple tools. I know about the fact GC collects memory but...
8
by: Chad | last post by:
hello, i am losing memory each time i make this call to a C++ dll (I make frequent calls). 'in VB.Net Declare Function grab Lib "grabber.dll" _ (ByRef lpBuf As Byte, ByVal lnum As Integer)...
1
by: trialproduct2004 | last post by:
Hi all, I am having slight confusion regarding memory management in .net. Say suppose i have two application one is in C# and other is in MFC(VC++). Both of this application are using lots...
0
by: erez_acount | last post by:
***************************************************************************** Call For Papers The 2006 International Symposium on Memory Management (ISMM'06) Co-located with PLDI 2006 ...
94
by: smnoff | last post by:
I have searched the internet for malloc and dynamic malloc; however, I still don't know or readily see what is general way to allocate memory to char * variable that I want to assign the substring...
3
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". ...
9
by: benoit808 | last post by:
I don't have a lot of experience with C++ so I apologize if this is a stupid question. I use Paul Nettle's memory manager (mmgr.cpp) which reports a memory leak but I don't think there's one. Here...
5
by: kumarmdb2 | last post by:
Hi guys, For last few days we are getting out of private memory error. We have a development environment. We tried to figure out the problem but we believe that it might be related to the OS...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.