Browse Source

Small fixes on errors and warnings.

Ioannis Koutras 13 years ago
parent
commit
c7f6a76c1f

+ 8 - 9
examples/larson.c

@@ -30,7 +30,7 @@ typedef struct thr_data {
     int max_size;
 
     char **array;
-    int *blksize;
+    long *blksize;
     int asize;
 
     int cAllocs;
@@ -47,16 +47,15 @@ int volatile stopflag = FALSE;
 int min_size = 10, max_size = 500;
 struct lran2_st rgen;
 char *blkp[MAX_BLOCKS];
-int blksize[MAX_BLOCKS];
+long blksize[MAX_BLOCKS];
 
 static void QueryPerformanceFrequency(long *x) {
     *x = 1000000L;
 }
 
 static void QueryPerformanceCounter (long *x) {
-    struct timezone tz;
     struct timeval tv;
-    gettimeofday(&tv, &tz);
+    gettimeofday(&tv, NULL);
     *x = tv.tv_sec * 1000000L + tv.tv_usec;
 }
 
@@ -76,8 +75,8 @@ static void _beginthread(VoidFunction x, void * z) {
 
 static void warmup(char **blkp, int num_chunks) {
     int cblks;
-    int victim;
-    int blk_size;
+    long victim;
+    long blk_size;
     LPVOID tmp;
 
     for(cblks = 0; cblks < num_chunks; cblks++) {
@@ -109,7 +108,7 @@ static void warmup(char **blkp, int num_chunks) {
 static void * exercise_heap( void *pinput) {
     thread_data  *pdea;
     int           cblks = 0;
-    int           victim;
+    long          victim;
     long          blk_size;
     int           range;
 
@@ -234,7 +233,7 @@ static void runthreads(long sleep_cnt, int min_threads, int max_threads, int chp
         }
 
         ticks = end_cnt - start_cnt ;
-        duration = (double)ticks/ticks_per_sec ;
+        duration = (double)(ticks/ticks_per_sec);
 
         for(i = 0; i < num_threads; i++) {
             if( !de_area[i].finished ) {
@@ -254,7 +253,7 @@ static void runthreads(long sleep_cnt, int min_threads, int max_threads, int chp
         printf("%6.3f", duration  ) ;
         printf("%6.3f", rate_n/rate_1 ) ;
         printf("%8.0f", sum_allocs/duration ) ;
-        printf(" %6.3f %.3f", (double)used_space/(1024*1024), used_space/reqd_space) ;
+        printf(" %6.3f %.3f", (double)(used_space/(1024*1024)), (used_space/reqd_space)
         printf("\n") ;
 
         Sleep(5000L) ; // wait 5 sec for old threads to die

+ 1 - 1
examples/lran2.h

@@ -34,7 +34,7 @@ lran2_init(struct lran2_st* d, long seed)
 	static 
 long lran2(struct lran2_st* d)
 {
-	int j = (d->y % 97);
+	long j = (d->y % 97);
 
 	d->y = d->v[j];
 	d->x = (IA*d->x + IC) % LRAN2_MAX;

+ 4 - 4
include/dmmlib/heap.h

@@ -53,10 +53,10 @@ typedef struct maptable_node_s {
 
 /** Statistics data structure. */
 typedef struct dmmstats_s {
-	uint32_t max_mem_allocated; /**< Maximum total memory allocated. */
-	uint32_t max_mem_requested; /**< Maximum total memory requested. */
-	uint32_t mem_allocated; /**< Total memory currently allocated. */
-	uint32_t mem_requested; /**< Total memory currently requested. */
+	size_t max_mem_allocated; /**< Maximum total memory allocated. */
+	size_t max_mem_requested; /**< Maximum total memory requested. */
+	size_t mem_allocated; /**< Total memory currently allocated. */
+	size_t mem_requested; /**< Total memory currently requested. */
 	uint32_t live_objects; /**< Number of the currently used blocks. */
 	uint32_t read_mem_accesses; /**< Number of read accesses. */
 	uint32_t write_mem_accesses; /**< Number of write accesses. */

+ 1 - 2
src/custom_free.c

@@ -61,6 +61,7 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
     heap->dmm_stats.mem_requested -= get_requested_size(ptr);
 
 #if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
+    coalesced = false;
     if(is_previous_free(ptr)) {
         if(get_owner(ptr) == get_owner(get_dlprevious(ptr))) {
 
@@ -77,13 +78,11 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
                 coalesced = true;
             } else {
                 mark_free(ptr);
-                coalesced = false;
             }
 
         }
     } else {
         mark_free(ptr);
-        coalesced = false;
     }
 #endif /* COALESCING_FIXED || COALESCING_VARIABLE */
 

+ 6 - 6
src/dmm_adaptor.c

@@ -56,19 +56,19 @@ void update_frag_params(heap_t *heap) {
 void update_foot_params(heap_t *heap) {
     switch(heap->dmm_knobs.foot_state) {
         default :
-            heap->dmm_knobs.empty_threshold = 0.8;
+            heap->dmm_knobs.empty_threshold = 0.8f;
             break;
         case 2 :
-            heap->dmm_knobs.empty_threshold = 0.6;
+            heap->dmm_knobs.empty_threshold = 0.6f;
             break;
         case 3 :
-            heap->dmm_knobs.empty_threshold = 0.4;
+            heap->dmm_knobs.empty_threshold = 0.4f;
             break;
         case 4 :
-            heap->dmm_knobs.empty_threshold = 0.2;
+            heap->dmm_knobs.empty_threshold = 0.2f;
             break;
         case 5 :
-            heap->dmm_knobs.empty_threshold = 0.0;
+            heap->dmm_knobs.empty_threshold = 0.0f;
             break;
     }
 }
@@ -77,7 +77,7 @@ float get_current_fragmentation(heap_t *heap) {
     float fragmentation;
 
     fragmentation = (float) heap->dmm_stats.mem_allocated / 
-        (float)	heap->dmm_stats.mem_requested - 1.0;
+        (float)	heap->dmm_stats.mem_requested - 1.0f;
 
     if(fragmentation <= MIN_FRAG_THRESHOLD &&
             heap->dmm_stats.mem_allocated < heap->dmm_knobs.mem_threshold) {

+ 5 - 0
src/linked_lists/search_algorithms.c

@@ -61,6 +61,8 @@ void * best_fit_on_freelist(heap_t *heap, size_t requested_size) {
     void *best_block, *best_previous_block;
     size_t best_size;
 
+    previous_block = NULL;
+    best_previous_block = NULL;
     ptr = NULL;
     best_block = NULL;
     best_size = (size_t) -1; /* SIZE_MAX */
@@ -81,6 +83,7 @@ void * best_fit_on_freelist(heap_t *heap, size_t requested_size) {
     } 
 
     /* Remove the block from the list */
+    /* Note: remove_block() is not used because the block is already found */
     if(best_block != NULL) {
         if(best_block == heap->free_list_head) {
             heap->free_list_head = get_next(best_block);
@@ -107,6 +110,7 @@ void * best_fit_on_freelist(heap_t *heap, size_t requested_size) {
 void * exact_fit_on_freelist(heap_t *heap, size_t requested_size) {
     void *current_block, *previous_block, *ptr;
 
+    previous_block = NULL;
     ptr = NULL;
 
     for(current_block = heap->free_list_head; current_block != NULL;
@@ -140,6 +144,7 @@ void * exact_fit_on_freelist(heap_t *heap, size_t requested_size) {
 void * first_fit_on_freelist(heap_t *heap, size_t requested_size) {
     void *current_block, *previous_block, *ptr;
 
+    previous_block = NULL;
     ptr = NULL;
 
     for(current_block = heap->free_list_head; current_block != NULL;

+ 6 - 2
src/print_stats.c

@@ -25,9 +25,13 @@ void print_stats(allocator_t *allocator) {
 
     for(i = 0; i < NUM_HEAPS; i++) {
         printf("Heap %d statistics:\n", i);
+        printf("Total malloc() calls: %d\n",
+                (int) allocator->heaps[i].dmm_stats.num_malloc);
+        printf("Total free() calls: %d\n",
+                (int) allocator->heaps[i].dmm_stats.num_free);
         printf("Memory currently allocated: %d\n",
-                allocator->heaps[i].dmm_stats.mem_allocated);
+                (int) allocator->heaps[i].dmm_stats.mem_allocated);
         printf("Memory currently requested: %d\n",
-                allocator->heaps[i].dmm_stats.mem_requested);
+                (int) allocator->heaps[i].dmm_stats.mem_requested);
     }
 }