Thursday, April 3, 2008

Memory

I just finished a C tutorial at theococoa.com.  The biggest difference it talked about between C and PHP is memory.  In PHP you can just create an array and then use it, its the same as making a variable.  In C, however, its much more complicated.  Every variable takes up a certain amount of memory and so in order to make a string, you need to allocate enough memory for multiple variables that make up a string.  So even a simple string is like an array in memory.  Then to create an array of strings is even more complicated because you need to create an array of arrays (or strings) and allocate that memory in the system.  For all of the arrays you first have to allocate the memory and then put data in it and then at the end you have to free it.  This is all completely new because PHP was a web language and really didn't deal with memory at all on the programming side.

No comments: