What is a memory leak?
I'd been thinking it means holes of unused RAM inside a thread's address space that develop as memory is allocated and deallocated during the thread's lifetime, similar to the holes that develop in the filesystems of certain operating systems (and must be defragmented). But I might be wrong.
I realize this discussion is going somewhat outside the context of my original question and am okay with that.
Yes, ejeffrey, you're right--I'm fuzzy on the whole idea of garbage collection.
"delete is the opposite of garbage collection. Garbage collection is a system that keeps track of all the pointers to objects, and when the last pointer goes out of scope, the object is automatically deleted, and its memory and hopefully other resources are freed. "
So all I need to do is use new and delete statements in my code, and the linker automagically links code into the executable to invoke this "system" --based on object size --to allocate and deallocate memory as needed, eh?
nctnico,
Thanks for the example. I think I understand now. That's done by hidden code inserted by the C++ linker at link time, I'd imagine.
So the way to have "global variables" available at all times to all objects during the lifetime of main() is to define them in the public section of objects declared prior to int main() in my source code?
I share your enthusiasm for avoiding or minimizing dynamic memory allocation/deallocation, and with code in general.
I am not familiar with the STL libraries, but will search for them on the web. Same with linked-list templates.
Thanks, AntiProtonBoy, for that illustrative example. I understand assignment of objects to
existing objects (deep copying) requires writing a method for the equals operator and overloading it within the context of my object's definition. I hope I remember! I appreciate your taking time to write that example. I think I understand now.
Thanks, IanB, for cluing me in on exception handlers. I take it they operate in a similar, architecture-dependent fashion to interrupt handlers, namely,
(1) You set up the ESR to be linked to a specific physical memory address inside the thread.
(2) You enable/disable the ESR by writing a specific bit pattern to a specific register in the CPU.
(3) You're responsible for any "special" response to the hardware exception by putting a jump to the corresponding code into the ESR.
(4) The program counter continues with the thread's next instruction when control is returned from the ESR.