Revision: 34404
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at October 22, 2010 02:38 by verhaeg
Initial Code
char *variable; int size = 120, tmpsize = 0; variable = (char *)malloc(size*sizeof(char)); while ( ... ) { //Realloc memory tmpsize += 40; if (tmpsize > size) { size += 120; variable = (char *)realloc(variable, size*sizeof(char)); } strcat(variable,"your string to add with a fixed size"); }
Initial URL
Initial Description
Realloc memory at every X steps. Useful when allocating fixed number of items (in this case chars).
Initial Title
Memory reallocation
Initial Tags
Initial Language
C