I'm new to C and trying to get my arms around memory allocation.
1. How much memory do I have allocated (including any/all variables) just before I call free() ?
2. How much do I have allocated (including any/all variables) after I call free?
3. When I make strOrig = dest what happens?
Does it just repoint or reset the value of the original memory?
What happens to the malloc allocated space?
Obviously, I'm trying to allocate as little memory as possible, using as little processing as possible. Also, I need to be able to free it when I'm done.
I'm trying to create a Binary Search Tree in the long run.
Code:char *subStr(char *strOrig, int nStart) { static char dest[4096]; strcpy(dest, strOrig + nStart); strOrig = dest; return strOrig; } int main() { char *buffer = malloc(250); buffer = "http://www.softlinksys.com/Programming/aspnet.php"; printf("\nSize: %d %s\n", (int)buffer, buffer); buffer = subStr(buffer, 7); printf("\nSize: %d %s\n", (int)buffer, buffer); free(buffer); return 0; }



LinkBack URL
About LinkBacks



