You are here:

C++/Memory Management


Is there any way I can see the compiler generated code for me.( c++/Unix )
I want to know in deatils how memory management is carried on .. I mean can you suugest me a website for it ...  

Your question may not help with what you want.

As to whether you can see the code generated by your compiler - that depends on the compiler you are using. The same goes as to how you would instruct the compiler do this.

Note that telling me you are using C++ on UN*X does not help too much. Each flavour of UN*X has one or more compilers supplied by the vendor and then there are third party compilers such as the GNU and KAI/Intel compilers.

With many UN*X compilers I know you used to be able to obtain C code output which can then be compiled through a C compiler before linking.

I also know that you can obtain an assembler listing output for the GNU compiler using the -S command line option (compile but do not assemble or link) - as this produces an assembler input file as the compilation output. Other UN*X compilers may have the same or a similar command line option. Note though that you _will_ need to understand the assembler language the compiler generates files for, and that unravelling compiler generated code is not that easy. I would also suggest you turn off all optimisations as this will only obfuscate the assembler code further.

The other options are to disassemble an executable or object file or to view running code in a suitable debugger.

That answers your question. However, it will not necessarily get you the information that you then go on to state you are interested in - memory management.

If the part of memory management you are interesting in is the dynamic memory allocation / deallocation handling by your C++ compiler you may have to look in the C and/or C++ run time language support libraries. Many C++ implementations of the default global operators new and delete simply wrap (or use pretty much the same code as) the C malloc/free functions to obtain raw memory and then call constructors of the objects to be created or call the destructors of those being destroyed before returning a raw memory block.

Another area to look in is the implementation of, and add-ons to, the standard C++ library as many of the class templates in this library take an allocator type as one of the template parameters. The default ones rely on the new and delete operators, but some suppliers have additional allocators available (possibly as a separate product - see for an example).

Also remember that individual classes can provide their own new and delete operator functions and the global operator new and delete functions can be replaced. In these case you would additionally need to look at the C++ source to sort out what is going on.

Finally, you will in most cases find that the C/C++ language support for dynamic memory management will sit on top of the operating system support. This will of course be true UN*X systems.

As you do not say why you wish to know about this area I cannot help further. If it is just for academic reasons then you should probably also get hold of some books on compilers and operating system technicalities.

As to web sites and other resources - well I would suggest you check out your compiler vendor / supplier site and documentation as a first port of call.

If you require the details of their runtime library then you may have to see if they supply the source code for it (but they may charge a fee).

The GNU compiler site can be found at and you should be able to download the source code for it and its libraries. Note the compiler support library is called libgcc. You should be able to dig out lots of compiler internals information here as well (see the documentation page You might also like to browse the links on their further readings page at

Specifically I found that GCC can produce builtin (intrinsic) functions for malloc and free, otherwise (as far as I can tell) it relies on a version of the C runtime library (libc) supplied with the OS - or maybe as a 3rd party version such as the GNU C library (which probably is the standard OS C library for the likes of GNU/Linux and HURD). I suspect it emits code sequences around calls to malloc and free for default operator new and delete support in C++, but could not dig out any explicit information on this. So in this case you would have to read the assembler output - or do more research than I did into the documentation and sources.

Hope this is of use and happy hunting...


All Answers

Answers by Expert:

Ask Experts


Ralph McArdell


I am a software developer with more than 15 years C++ experience and over 25 years experience developing a wide variety of applications for Windows NT/2000/XP, UNIX, Linux and other platforms. I can help with basic to advanced C++, C (although I do not write just-C much if at all these days so maybe ask in the C section about purely C matters), software development and many platform specific and system development problems.


My career started in the mid 1980s working as a batch process operator for the now defunct Inner London Education Authority, working on Prime mini computers. I then moved into the role of Programmer / Analyst, also on the Primes, then into technical support and finally into the micro computing section, using a variety of 16 and 8 bit machines. Following the demise of the ILEA I worked for a small company, now gone, called Hodos. I worked on a part task train simulator using C and the Intel DVI (Digital Video Interactive) - the hardware based predecessor to Indeo. Other projects included a CGI based train simulator (different goals to the first), and various other projects in C and Visual Basic (er, version 1 that is). When Hodos went into receivership I went freelance and finally managed to start working in C++. I initially had contracts working on train simulators (surprise) and multimedia - I worked on many of the Dorling Kindersley CD-ROM titles and wrote the screensaver games for the Wallace and Gromit Cracking Animator CD. My more recent contracts have been more traditionally IT based, working predominately in C++ on MS Windows NT, 2000. XP, Linux and UN*X. These projects have had wide ranging additional skill sets including system analysis and design, databases and SQL in various guises, C#, client server and remoting, cross porting applications between platforms and various client development processes. I have an interest in the development of the C++ core language and libraries and try to keep up with at least some of the papers on the ISO C++ Standard Committee site at


©2017 All rights reserved.