16 #include "pol_global_config.h" 25 #define MEMORYLOGBLOCKS 0 38 static unsigned int requested_8 = 0;
39 static unsigned int requested_16 = 0;
40 static unsigned int requested_32 = 0;
41 static unsigned int requested_64 = 0;
42 static unsigned int requested_128 = 0;
43 static unsigned int requested_512 = 0;
44 static unsigned int requested_1024 = 0;
45 static unsigned int requested_2048 = 0;
46 static unsigned int requested_4096 = 0;
47 static unsigned int requested_8192 = 0;
48 static unsigned int requested_16384 = 0;
49 static unsigned int requested_65536 = 0;
50 static unsigned int requested_131072 = 0;
51 static unsigned int requested_524288 = 0;
52 static unsigned int requested_1048576 = 0;
53 static unsigned int requested_16777216 = 0;
54 static unsigned int requested_huge = 0;
56 static unsigned int used_8 = 0;
57 static unsigned int used_16 = 0;
58 static unsigned int used_32 = 0;
59 static unsigned int used_64 = 0;
60 static unsigned int used_128 = 0;
61 static unsigned int used_512 = 0;
62 static unsigned int used_1024 = 0;
63 static unsigned int used_2048 = 0;
64 static unsigned int used_4096 = 0;
65 static unsigned int used_8192 = 0;
66 static unsigned int used_16384 = 0;
67 static unsigned int used_65536 = 0;
68 static unsigned int used_131072 = 0;
69 static unsigned int used_524288 = 0;
70 static unsigned int used_1048576 = 0;
71 static unsigned int used_16777216 = 0;
72 static unsigned int used_huge = 0;
74 static unsigned int allocated_8 = 0;
75 static unsigned int allocated_16 = 0;
76 static unsigned int allocated_32 = 0;
77 static unsigned int allocated_64 = 0;
78 static unsigned int allocated_128 = 0;
79 static unsigned int allocated_512 = 0;
80 static unsigned int allocated_1024 = 0;
81 static unsigned int allocated_2048 = 0;
82 static unsigned int allocated_4096 = 0;
83 static unsigned int allocated_8192 = 0;
84 static unsigned int allocated_16384 = 0;
85 static unsigned int allocated_65536 = 0;
86 static unsigned int allocated_131072 = 0;
87 static unsigned int allocated_524288 = 0;
88 static unsigned int allocated_1048576 = 0;
89 static unsigned int allocated_16777216 = 0;
90 static unsigned int allocated_huge = 0;
96 static unsigned int n_allocs;
97 static unsigned int n_frees;
98 void*
operator new(
size_t len )
100 void *vp = malloc( len );
104 bytes_allocated += _msize( vp );
106 bytes_allocated += malloc_usable_size( vp );
113 throw std::runtime_error(
"Out of memory" );
117 void operator delete(
void *ptr )
122 bytes_allocated -= _msize( ptr );
124 bytes_allocated -= malloc_usable_size( ptr );
135 void* do_new(
size_t len )
137 void* vp = malloc( len );
143 len = malloc_usable_size( vp );
172 else if ( len < 128 )
176 allocated_128 += len;
178 else if ( len < 512 )
182 allocated_512 += len;
184 else if ( len < 1024 )
188 allocated_1024 += len;
190 else if ( len < 2048 )
194 allocated_2048 += len;
196 else if ( len < 4096 )
200 allocated_4096 += len;
202 else if ( len < 8192 )
206 allocated_8192 += len;
208 else if ( len < 16384 )
212 allocated_16384 += len;
214 else if ( len < 65536 )
218 allocated_65536 += len;
220 #if MEMORYLOGBLOCKS == 1 222 LEAKLOG.Format(
"New 64 KB {:x} {}\n" ) << vp << len;
224 LEAKLOG.Format(
"New 64 KB {:x} {} {} {} {} {} {} {} {} {}\n" )
225 << vp << len << __builtin_return_address( 0 ) << __builtin_return_address( 1 )
226 << __builtin_return_address( 2 ) << __builtin_return_address( 3 )
227 << __builtin_return_address( 4 ) << __builtin_return_address( 5 )
228 << __builtin_return_address( 6 ) << __builtin_return_address( 7 );
232 else if ( len < 131072 )
236 allocated_131072 += len;
238 else if ( len < 524288 )
242 allocated_524288 += len;
244 #if MEMORYLOGBLOCKS == 1 246 LEAKLOG.Format(
"New 0.5 MB {:x} {}\n" ) << vp << len;
248 LEAKLOG.Format(
"New 0.5 M {:x} {} {} {} {} {} {} {} {} {}\n" )
249 << vp << len << __builtin_return_address( 0 ) << __builtin_return_address( 1 )
250 << __builtin_return_address( 2 ) << __builtin_return_address( 3 )
251 << __builtin_return_address( 4 ) << __builtin_return_address( 5 )
252 << __builtin_return_address( 6 ) << __builtin_return_address( 7 );
256 else if ( len < 1048576 )
260 allocated_1048576 += len;
262 else if ( len < 16777216 )
264 requested_16777216++;
266 allocated_16777216 += len;
272 allocated_huge += len;
274 #if MEMORYLOGBLOCKS == 1 276 LEAKLOG.Format(
"New huge {:x} {}\n" ) << vp << len;
278 LEAKLOG.Format(
"New huge {:x} {} {} {} {} {} {} {} {} {}\n" )
279 << vp << len << __builtin_return_address( 0 ) << __builtin_return_address( 1 )
280 << __builtin_return_address( 2 ) << __builtin_return_address( 3 )
281 << __builtin_return_address( 4 ) << __builtin_return_address( 5 )
282 << __builtin_return_address( 6 ) << __builtin_return_address( 7 );
287 bytes_allocated += len;
293 throw std::runtime_error(
"Out of memory" );
298 void do_delete(
void* ptr )
303 size_t len = _msize( ptr );
305 size_t len = malloc_usable_size( ptr );
330 else if ( len < 128 )
333 allocated_128 -= len;
335 else if ( len < 512 )
338 allocated_512 -= len;
340 else if ( len < 1024 )
343 allocated_1024 -= len;
345 else if ( len < 2048 )
348 allocated_2048 -= len;
350 else if ( len < 4096 )
353 allocated_4096 -= len;
355 else if ( len < 8192 )
358 allocated_8192 -= len;
360 else if ( len < 16384 )
363 allocated_16384 -= len;
365 else if ( len < 65536 )
368 allocated_65536 -= len;
370 #if MEMORYLOGBLOCKS == 1 372 LEAKLOG.Format(
"Delete 64 KB {:x} {}\n" ) << ptr << len;
374 LEAKLOG.Format(
"Delete 64 KB {:x} {} {} {} {} {} {} {} {} {}\n" )
375 << ptr << len << __builtin_return_address( 0 ) << __builtin_return_address( 1 )
376 << __builtin_return_address( 2 ) << __builtin_return_address( 3 )
377 << __builtin_return_address( 4 ) << __builtin_return_address( 5 )
378 << __builtin_return_address( 6 ) << __builtin_return_address( 7 );
382 else if ( len < 131072 )
385 allocated_131072 -= len;
387 else if ( len < 524288 )
390 allocated_524288 -= len;
392 #if MEMORYLOGBLOCKS == 1 394 LEAKLOG.Format(
"Delete 0.5 MB {:x} {}\n" ) << ptr << len;
396 LEAKLOG.Format(
"Delete 0.5 MB {:x} {} {} {} {} {} {} {} {} {}\n" )
397 << ptr << len << __builtin_return_address( 0 ) << __builtin_return_address( 1 )
398 << __builtin_return_address( 2 ) << __builtin_return_address( 3 )
399 << __builtin_return_address( 4 ) << __builtin_return_address( 5 )
400 << __builtin_return_address( 6 ) << __builtin_return_address( 7 );
404 else if ( len < 1048576 )
407 allocated_1048576 -= len;
409 else if ( len < 16777216 )
412 allocated_16777216 -= len;
417 allocated_huge -= len;
419 #if MEMORYLOGBLOCKS == 1 421 LEAKLOG.Format(
"Delete huge {:x} {}\n" ) << ptr << len;
423 LEAKLOG.Format(
"Delete huge {:x} {} {} {} {} {} {} {} {} {}\n" )
424 << ptr << len << __builtin_return_address( 0 ) << __builtin_return_address( 1 )
425 << __builtin_return_address( 2 ) << __builtin_return_address( 3 )
426 << __builtin_return_address( 4 ) << __builtin_return_address( 5 )
427 << __builtin_return_address( 6 ) << __builtin_return_address( 7 );
432 bytes_allocated -= len;
448 INFO_PRINT <<
"OpNewHeap: allocated " << blocks_allocated <<
" blocks, " << bytes_allocated
450 <<
"OpNewHeap: delta " << delta_blocks <<
" blocks, " << delta_bytes <<
" bytes\n";
453 DEBUGLOG <<
"Heap (whole): " << blocks_allocated <<
" blocks with " << bytes_allocated
455 <<
"Heap (delta): " << delta_blocks <<
" blocks with " << delta_bytes <<
" Bytes\n" 456 <<
"Heap (blocks): " << used_8 <<
" of " << requested_8 <<
" blocks of 8 Byte (" 457 << allocated_8 <<
")\n" 458 <<
"Heap (blocks): " << used_16 <<
" of " << requested_16 <<
" blocks of 16 Byte (" 459 << allocated_16 <<
")\n" 460 <<
"Heap (blocks): " << used_32 <<
" of " << requested_32 <<
" blocks of 32 Byte (" 461 << allocated_32 <<
")\n" 462 <<
"Heap (blocks): " << used_64 <<
" of " << requested_64 <<
" blocks of 64 Byte (" 463 << allocated_64 <<
")\n" 464 <<
"Heap (blocks): " << used_128 <<
" of " << requested_128 <<
" blocks of 128 Byte (" 465 << allocated_128 <<
")\n" 466 <<
"Heap (blocks): " << used_512 <<
" of " << requested_512 <<
" blocks of 512 Byte (" 467 << allocated_512 <<
")\n" 468 <<
"Heap (blocks): " << used_1024 <<
" of " << requested_1024 <<
" blocks of 1 KByte (" 469 << allocated_1024 <<
")\n" 470 <<
"Heap (blocks): " << used_2048 <<
" of " << requested_2048 <<
" blocks of 2 KByte (" 471 << allocated_2048 <<
")\n" 472 <<
"Heap (blocks): " << used_4096 <<
" of " << requested_4096 <<
" blocks of 4 KByte (" 473 << allocated_4096 <<
")\n" 474 <<
"Heap (blocks): " << used_8192 <<
" of " << requested_8192 <<
" blocks of 8 KByte (" 475 << allocated_8192 <<
")\n" 476 <<
"Heap (blocks): " << used_16384 <<
" of " << requested_16384
477 <<
" blocks of 16 KByte (" << allocated_16384 <<
")\n" 478 <<
"Heap (blocks): " << used_65536 <<
" of " << requested_65536
479 <<
" blocks of 64 KByte (" << allocated_65536 <<
")\n" 480 <<
"Heap (blocks): " << used_131072 <<
" of " << requested_131072
481 <<
" blocks of 128 KByte (" << allocated_131072 <<
")\n" 482 <<
"Heap (blocks): " << used_524288 <<
" of " << requested_524288
483 <<
" blocks of 0.5 MByte (" << allocated_524288 <<
")\n" 484 <<
"Heap (blocks): " << used_1048576 <<
" of " << requested_1048576
485 <<
" blocks of 1 MByte (" << allocated_1048576 <<
")\n" 486 <<
"Heap (blocks): " << used_16777216 <<
" of " << requested_16777216
487 <<
" blocks of 16 MByte (" << allocated_16777216 <<
")\n" 488 <<
"Heap (blocks): " << used_huge <<
" of " << requested_huge <<
" huge blocks (" 489 << allocated_huge <<
")\n";
492 LEAKLOG << blocks_allocated <<
"; " << bytes_allocated <<
"; " << delta_blocks <<
";" 493 << delta_bytes <<
";" << used_8 <<
";" << requested_8 <<
";" << allocated_8 <<
";" 494 << used_16 <<
";" << requested_16 <<
";" << allocated_16 <<
";" << used_32 <<
";" 495 << requested_32 <<
";" << allocated_32 <<
";" << used_64 <<
";" << requested_64 <<
";" 496 << allocated_64 <<
";" << used_128 <<
";" << requested_128 <<
";" << allocated_128 <<
";" 497 << used_512 <<
";" << requested_512 <<
";" << allocated_512 <<
";" << used_1024 <<
";" 498 << requested_1024 <<
";" << allocated_1024 <<
";" << used_2048 <<
";" << requested_2048
499 <<
";" << allocated_2048 <<
";" << used_4096 <<
";" << requested_4096 <<
";" 500 << allocated_4096 <<
";" << used_8192 <<
";" << requested_8192 <<
";" << allocated_8192
501 <<
";" << used_16384 <<
";" << requested_16384 <<
";" << allocated_16384 <<
";" 502 << used_65536 <<
";" << requested_65536 <<
";" << allocated_65536 <<
";" << used_131072
503 <<
";" << requested_131072 <<
";" << allocated_131072 <<
";" << used_524288 <<
";" 504 << requested_524288 <<
";" << allocated_524288 <<
";" << used_1048576 <<
";" 505 << requested_1048576 <<
";" << allocated_1048576 <<
";" << used_16777216 <<
";" 506 << requested_16777216 <<
";" << allocated_16777216 <<
";" << used_huge <<
";" 507 << requested_huge <<
";" << allocated_huge <<
"\n";
514 void*
operator new(
size_t len )
516 return Pol::Clib::do_new( len );
519 void*
operator new[](
size_t len )
521 return Pol::Clib::do_new( len );
524 void operator delete(
void* ptr )
526 Pol::Clib::do_delete( ptr );
529 void operator delete[](
void* ptr )
531 Pol::Clib::do_delete( ptr );
static unsigned int blocks_allocated
static unsigned int last_blocks_allocated
static unsigned int last_bytes_allocated
static unsigned int bytes_allocated