Changeset 149 for trunk/src/sh_mem.c
- Timestamp:
- Jan 7, 2008, 8:52:13 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_mem.c
r144 r149 47 47 #undef FIL__ 48 48 #define FIL__ _("sh_mem.c") 49 static int eblock = 0;50 49 51 50 #ifdef MEM_DEBUG … … 74 73 unsigned long Mem_Current = 0, Mem_Max = 0; 75 74 76 #if 077 #define MEM_DETAILS78 #endif79 80 #ifdef MEM_DETAILS81 int max_upto_032 = 0;82 int max_upto_064 = 0;83 int max_upto_128 = 0;84 int max_upto_256 = 0;85 int max_upto_512 = 0;86 int max_upto_1024 = 0;87 int max_upto_4096 = 0;88 int max_upto_inf = 0;89 90 int now_upto_032 = 0;91 int now_upto_064 = 0;92 int now_upto_128 = 0;93 int now_upto_256 = 0;94 int now_upto_512 = 0;95 int now_upto_1024 = 0;96 int now_upto_4096 = 0;97 int now_upto_inf = 0;98 99 int tot_upto_032 = 0;100 int tot_upto_064 = 0;101 int tot_upto_128 = 0;102 int tot_upto_256 = 0;103 int tot_upto_512 = 0;104 int tot_upto_1024 = 0;105 int tot_upto_4096 = 0;106 int tot_upto_inf = 0;107 #endif108 109 75 #ifdef HAVE_PTHREAD 110 76 SH_MUTEX_RECURSIVE(mutex_mem); 111 77 #endif 112 78 79 /* define MEM_LOG to an absolute filename to enable this */ 113 80 #ifdef MEM_LOG 114 81 void sh_mem_dump () 115 82 { 116 83 memlist_t * this = memlist; 117 118 119 84 FILE * fd; 120 85 … … 123 88 124 89 fd = fopen(MEM_LOG, "w"); 90 if (!fd) 91 { 92 perror(MEM_LOG); 93 _exit(EXIT_FAILURE); 94 } 125 95 126 96 while (this != NULL) 127 97 { 128 fprintf (fd, "%20s %5d %ld\n", this->file, this->line, this->size); 98 fprintf (fd, "## %20s %5d %ld\n", this->file, this->line, this->size); 99 fprintf (fd, "%10p %8ld\n", (void *)this->address, this->size); 129 100 this = this->next; 130 101 } 131 102 fclose(fd); 132 SH_MUTEX_RECURSIVE_UNLOCK(mutex_mem); 133 return; 103 104 SH_MUTEX_RECURSIVE_UNLOCK(mutex_mem); 105 _exit(EXIT_SUCCESS); 134 106 } 135 107 #else … … 162 134 Mem_Max, Mem_Current); 163 135 164 #ifdef MEM_DETAILS165 fprintf(stderr, "\n");166 fprintf(stderr, "__SIZE_____TOTAL___MAXIMUM___\n");167 fprintf(stderr, " 32 %6d %6d\n", tot_upto_032, max_upto_032);168 fprintf(stderr, " 64 %6d %6d\n", tot_upto_064, max_upto_064);169 fprintf(stderr, " 128 %6d %6d\n", tot_upto_128, max_upto_128);170 fprintf(stderr, " 256 %6d %6d\n", tot_upto_256, max_upto_256);171 fprintf(stderr, " 512 %6d %6d\n", tot_upto_512, max_upto_512);172 fprintf(stderr, " 1024 %6d %6d\n", tot_upto_1024, max_upto_1024);173 fprintf(stderr, " 4096 %6d %6d\n", tot_upto_4096, max_upto_4096);174 fprintf(stderr, " inf %6d %6d\n", tot_upto_inf, max_upto_inf);175 fprintf(stderr, "\n");176 #endif177 178 136 this = memlist; 179 137 … … 199 157 SH_MUTEX_RECURSIVE_INIT(mutex_mem); 200 158 SH_MUTEX_RECURSIVE_LOCK(mutex_mem); 159 201 160 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_MSTAMP, 202 161 Mem_Max, Mem_Current); … … 229 188 } 230 189 231 /* if (nerr > 0) abort(); */232 190 233 191 SH_MUTEX_RECURSIVE_UNLOCK(mutex_mem); … … 249 207 if ( the_realAddress == NULL ) 250 208 { 251 if (eblock == 0) 252 { 253 eblock = 1; 254 (void) safe_logger (0, 0, NULL); 255 eblock = 0; 256 } 209 (void) safe_logger (0, 0, NULL); 210 257 211 /* use _exit() rather than exit() - we malloc() in atexit() functions 258 212 */ 259 _exit ( 42);213 _exit (EXIT_FAILURE); 260 214 } 261 215 … … 274 228 Max_Alloc_Count = Now_Alloc_Count; 275 229 276 #ifdef MEM_DETAILS277 if (size <= 32)278 {279 ++now_upto_032;280 ++tot_upto_032;281 if (now_upto_032 > max_upto_032) max_upto_032 = now_upto_032;282 }283 else if (size <= 64)284 {285 ++now_upto_064;286 ++tot_upto_064;287 if (now_upto_064 > max_upto_064) max_upto_064 = now_upto_064;288 }289 else if (size <= 128)290 {291 ++now_upto_128;292 ++tot_upto_128;293 if (now_upto_128 > max_upto_128) max_upto_128 = now_upto_128;294 }295 else if (size <= 256)296 {297 ++now_upto_256;298 ++tot_upto_256;299 if (now_upto_256 > max_upto_256) max_upto_256 = now_upto_256;300 }301 else if (size <= 512)302 {303 ++now_upto_512;304 ++tot_upto_512;305 if (now_upto_512 > max_upto_512) max_upto_512 = now_upto_512;306 }307 else if (size <= 1024)308 {309 ++now_upto_1024;310 ++tot_upto_1024;311 if (now_upto_1024 > max_upto_1024) max_upto_1024 = now_upto_1024;312 }313 else if (size <= 4096)314 {315 ++now_upto_4096;316 ++tot_upto_4096;317 if (now_upto_4096 > max_upto_4096) max_upto_4096 = now_upto_4096;318 }319 else320 {321 ++now_upto_inf;322 ++tot_upto_inf;323 if (now_upto_inf > max_upto_inf) max_upto_inf = now_upto_inf;324 325 fprintf(stderr, "\n___BIGSIZE___");326 fprintf(stderr, " %6d -> %16s %10d \n", size, file, line);327 fprintf(stderr, "\n");328 329 }330 #endif331 332 230 Mem_Current += size; 333 231 Mem_Max = ( (Mem_Current > Mem_Max) ? Mem_Current : Mem_Max); … … 337 235 if ( this == NULL) 338 236 { 339 if (eblock == 0) 340 { 341 eblock = 1; 342 (void) safe_logger(0, 0, NULL); 343 eblock = 0; 344 } 345 _exit(42); 237 (void) safe_logger(0, 0, NULL); 238 239 _exit(EXIT_FAILURE); 346 240 } 347 241 else … … 374 268 SH_MUTEX_RECURSIVE_INIT(mutex_mem); 375 269 SH_MUTEX_RECURSIVE_LOCK(mutex_mem); 270 376 271 if ( a == NULL ) 377 272 { … … 424 319 --Now_Alloc_Count; 425 320 426 #ifdef MEM_DETAILS427 if (size <= 32)428 --now_upto_032;429 else if (size <= 64)430 --now_upto_064;431 else if (size <= 128)432 --now_upto_128;433 else if (size <= 256)434 --now_upto_256;435 else if (size <= 512)436 --now_upto_512;437 else if (size <= 1024)438 --now_upto_1024;439 else if (size <= 4096)440 --now_upto_4096;441 else442 --now_upto_inf;443 #endif444 445 321 Mem_Current -= size; 446 322 out: … … 475 351 theAddress = malloc(size); 476 352 477 if ( theAddress == NULL )478 { 479 if (eblock == 0)480 { 481 eblock = 1; 482 (void) safe_logger(0, 0, NULL); 483 eblock = 0;484 } 353 if ( theAddress != NULL ) 354 { 355 SL_RETURN( theAddress, _("sh_mem_malloc")); 356 } 357 else 358 { 359 (void) safe_logger(0, 0, NULL); 360 485 361 /* use _exit() rather than exit() - we malloc() in atexit() 486 362 */ 487 _exit (42); 488 } 489 /* memset (theAddress, 0, 1); *//* needs testing */ 490 491 SL_RETURN( theAddress, _("sh_mem_malloc")); 492 } 493 #endif 363 _exit (EXIT_FAILURE); 364 } 365 } 366 #endif
Note:
See TracChangeset
for help on using the changeset viewer.