int main(int argc, char *argv[]) { long num; long i; int size; int sum = 0; long overhead; struct mallinfo info; srand((unsigned int)time(NULL)); num = atol(argv[1]); for(i = 0; i < num; i++) { size = get_random_size(); malloc(size); sum += size; } fprintf(stderr, "Sum: %d\n", sum); malloc_stats(); info = mallinfo(); fprintf(stderr, "info.arena: %d\n", info.arena); overhead = info.arena - sum; fprintf(stderr, "%lu (%lu%%)\n", overhead, 100*overhead / info.arena); return 0; }
//creates random object properties and stores them in call-by-reference arguments void get_random_object_props(MContext *mc, size_t *size, unsigned int *liveness, unsigned int *num_objects, lifetime_size_class_type *type) { unsigned int lt = get_random_liveness(mc); unsigned int sz = get_random_size(mc); unsigned int sc = get_sizeclass(sz); unsigned int effect_of_sizeclass = (mc->gopts->max_object_sc - sc) + 1; effect_of_sizeclass *= effect_of_sizeclass; //quadratic impact unsigned int effect_of_liveness = (mc->gopts->max_liveness - lt) + 1; effect_of_liveness *= effect_of_liveness; //quadratic impact //output parameters *size = sz; *liveness = lt; *num_objects = effect_of_sizeclass * effect_of_liveness; assert(*num_objects > 0); assert(sz <= (BIT_ZERO << mc->gopts->max_object_sc)); *type = get_random_lifetime_size_class_type(mc); }
int main(int argc, char *argv[]) { void **ptrs; long num; long i; int loop; srand((unsigned int)time(NULL)); num = atol(argv[1]); ptrs = malloc(sizeof(void*) * num); for(i = 0; i < num; i++) { ptrs[i] = malloc(get_random_size()); } _reset_clock(); for(loop = 0; loop < NUM_LOOPS; loop++) { for(i = 0; i < num; i++) { if((rand() % 2) == 0) { free(ptrs[i]); ptrs[i] = NULL; } } for(i = 0; i < num; i++) { if(ptrs[i] == NULL) { _resume(); ptrs[i] = malloc(get_random_size()); _pause(); } } } _print_elapsed_time(); return 0; }