[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: memory management

>> I read C++ For Real Programmers and loved all the "here's how not to leak
>> memory" strategies. Tried them out, they make it practically impossible to
>> leak memory.
>I'd be really interested in those strategies and your own
>opinion/improvements on them.

It's all quite long and involved (about 1/3 of the book is about not leaking
memory in one way or another), and does some FASCINATING stuff. {One idiom I
loved so much I just rushed out and used it is a way of changing the type of an
object at run-time... I used it to make arrays of things that actually aren't
all the same object, which is handy at times.}

Basically, it's all about using counting references, and making "new"

I wrote an implementation for the Mac that used all this stuff. You could
allocate a block of memory and pass it around willy-nilly and when the last
reference goes out of scope the memory is deleted. You can't leak the memory
blocks at all. On the Mac you have to lock memory before giving it to certain
things, so I added the ability to create temporarily locked blocks of memory
that couldn't leak locks (common Mac error is to lock a handle and then forget
to unlock it) - but again, you had to create a lock on the heap, so you couldn't
NOT unlock it.

The stuff in the book goes deeper, deals with distributed objects and garbage
collection systems and all kinds of things - I'd definitely recommend getting
the book - I'd tell you the ISBN but I don't have it to hand. The author is Jeff

To be truthful, it's the first "advanced" level C++ book I've come across that
both wasn't woolley (there's full implementation of all the concepts - they're
not castles in the sky) and was actually advanced - although there's a couple of
chapters on C++ syntax and recent extensions, they still need good C++ knowledge
to start with to be useful. If Stroustroup is a mystery I'd guess this book
would be too.