4 ms·
#include <stdio.h> #include <stdlib.h> int main(){ int same=0; int moved=0; char* temp=malloc(16); for(int i=0; i<10000; i++){
by habibur 3y ago
#include <stdio.h>
#include <stdlib.h>
int main(){
int same=0;
int moved=0;
char* temp=malloc(16);
for(int i=0; i<10000; i++){
char* temp2=realloc(temp,(i+2)*16);
if(temp!=temp2){
moved++;
temp=temp2;
}
else same++;
}
printf("ptr moved %d, reused %d times\n",moved,same);
}
Tried the above. Ptr moved 7 times and is reused 9993 times.
But, what you want to test is what you identify as your need.
No point in explaining more.