Allocating Memory
I've used malloc(), free() and sizeof() without really describing how they should be used. Note that sizeof() is an operator, not a function. If it was a function it would be called at runtime. However as the compiler knows how big types and variables are (during compilation), it can substitute the actual size and use it during compilation.The functions malloc() and free() are closely tied in that malloc() requests memory from the operating system and free() returns memory allocated by malloc() back. When you use malloc() you should do the following:
- Specify the amount of RAM you need in the call, perhaps using sizeof().
- Check that the pointer returned is not NULL. This occurs if malloc() cannot allocate any RAM.
- Track the memory allocated, by keeping the original pointer or a copy of it and passing the pointer to free() when you no longer need the memory.

