views:

84

answers:

4

I came across this presentation while browsing SO some time ago, and it relates performance to specific memory allocation decisions. The author has some interesting diagrams that show how various objects are allocated by a C++ program, and goes on to optimise the program by making some changes in the code. His diagrams make sense in their own context, but I'd like to know more about how to draw my own.

Where can I learn more about how C++ allocates objects in memory? I would like to know how various structures (arrays, pointers, ints, etc...) are placed when I write a program, in detail. Related to this are pre-caching techniques such as _dcbt, which sound interesting as well.

+2  A: 

You should have no problem finding any number of sites with information on C++ memory allocation. Here is a small sample from a quick Google search:

Here are a couple of books that might be of interest to you as well:

Brandon E Taylor
+1  A: 

I recommand you the ultimate learning book of the C++ language:

C++ Programming Language, by Bjarne Stroustrup, the father of C++ language

http://www.amazon.com/Programming-Language-3rd-Bjarne-Stroustrup/dp/0201889544

shader
A: 

Doug Lea has page up describing the implementation of malloc. It is an old article but I think most of its is still relevant.

John Stanhope
+2  A: 

Note that C++ says very little about how object are allocated in memeory. All the implementation details are left to individual compilers vendors to work out for themselves.

So, while many techniques are common, none is guaranteed to be what is actaully used in your program.

James Curran