Hello!
I have an assignment to create datablocks of the sizes 100mb, 200,300..1000.
And its worth mentioning, im noob at C :P
Now my code looks like this:
Code:#include <stdio.h>#include <stdlib.h> #include <time.h> #include <sys/time.h> #include <assert.h> #include <unistd.h> #define KILO 1024 #define MEGA (KILO*KILO) #define INCREMENT 100 int diffTime(struct timeval * startTime, struct timeval * endTime) { return ((endTime->tv_sec - startTime->tv_sec)*1000 + (endTime->tv_usec- startTime->tv_usec)/1000); } int createDataBlock(long int storlek) { char * str; str = (char *) malloc(storlek); //free(str); return 1; } int main(void) { long int i; struct timeval startT, endT; struct timezone tzp; for(i=INCREMENT;i<=50000;i=i+INCREMENT){ gettimeofday(&startT, &tzp); /* hämta starttid */ createDataBlock(i); gettimeofday(&endT, &tzp); /* hämta sluttid */ printf("Datablock %ld MB took %d msek\n",i, diffTime(&startT,&endT)); //sleep(3); //printf("Tiden: %d", timeDiff); } return 0; }
Why isnt any memory being allocated, and how would one save the allocated memory to disk(to a file) if possible ?
PS: I just want to fill it with random data, I was hoping malloc would fill it with garbage ?