Created
July 30, 2012 19:19
-
-
Save danielsaad/3209326 to your computer and use it in GitHub Desktop.
Realloc copy operations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Total op = 10000 | |
Number of copy operations = 12 | |
Total op = 1000000 | |
Number of copy operations = 5941 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
const int REALLOC_SIZE = 10000; | |
const int IT = 1000000; | |
int main(){ | |
void* ptr=NULL; | |
void* last; | |
int n=0; | |
int i; | |
for(i=1;i<IT;i++){ | |
last = ptr; | |
ptr = realloc(ptr,REALLOC_SIZE*i); | |
if(last!=ptr) n++; | |
} | |
printf("Total op = %d\nNumber of copy operations = %d\n",IT,n); | |
return(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment