I am having problems with an array which i want to re-use in my program. I need to change the size dynamically and clear it. But unfortunately the resizing does not work.
uint8_t * readBuffer; // Create array pointer
readBuffer = (uint8_t *) malloc(4); // Mem. alloc. 4bytes
memset(readBuffer, 0, sizeof(readBuffer); // Reset array
// Do stuff
free(readBuffer) // Release mem. block
....
readBuffer = (uint8_t *) malloc(1) // Mem. alloc. 1byte
memset(readBuffer, 0, sizeof(readBuffer); // Reset array
// Do stuff
free(readBuffer) // Release mem. block
At the the resizing step the length of my array is still the former (4).
Am i using free
all wrong?
Further more is there much more efficient alternatives to memset
for clearing?
Thanks in advance.