Tuesday, September 28, 2004

C and Dynamic Allocation

Yeah

In C++, dynamic allocation is safer and easier to implement. In C things are not that easy or clear but they're more fun to program:

I was just playing a little with calloc functions and commented out the code enough so it explains it all well enough. I just used it with functions so that you can see where and how to use pratically dynamic allocation.

Check the code here...

It is easier to think about of it using abstraction at maximum, for example:

calloc( a , sizeof(int) ) will return a pointer to allocate enough memory for an array
of size a rather than trying to see those diagrams where the memory points to this and that.
Ok, after you getting this go ahead and try to grasp and grok those diagrams, but prior to it
you will know what it does...

No comments: