Pol  Revision:cb584c9
allocd.cpp
Go to the documentation of this file.
1 
8 #include "allocd.h"
9 
10 #include <cstddef>
11 #ifdef _WIN32
12 #include "../clib/logfacility.h"
13 #include <format/format.h>
14 #include <malloc.h>
15 #endif
16 
17 namespace Pol
18 {
19 namespace Core
20 {
21 size_t last_blocks_used = 0;
22 size_t last_bytes_used = 0;
23 size_t last_blocks_free = 0;
24 size_t last_bytes_free = 0;
25 
27 {
28 #ifdef _WIN32
29  _HEAPINFO hinfo;
30  int heapstatus;
31  hinfo._pentry = nullptr;
32  size_t blocks_used = 0, bytes_used = 0, blocks_free = 0, bytes_free = 0;
33  while ( ( heapstatus = _heapwalk( &hinfo ) ) == _HEAPOK )
34  {
35  if ( hinfo._useflag == _USEDENTRY )
36  {
37  ++blocks_used;
38  bytes_used += hinfo._size;
39  }
40  else
41  {
42  ++blocks_free;
43  bytes_free += hinfo._size;
44  }
45  }
46  fmt::Writer _tmp;
47  _tmp.Format( "Heap: Used {} blocks, {} bytes, Free {} blocks, {} bytes\n" )
48  << blocks_used << bytes_used << blocks_free << bytes_free;
49  _tmp.Format( "Delta: Used {} blocks, {} bytes, Free {} blocks, {} bytes\n" )
50  << ( blocks_used - last_blocks_used ) << ( bytes_used - last_bytes_used )
51  << ( blocks_free - last_blocks_free ) << ( bytes_free - last_bytes_free );
52  last_blocks_used = blocks_used;
53  last_bytes_used = bytes_used;
54  last_blocks_free = blocks_free;
55  last_bytes_free = bytes_free;
56 
57  switch ( heapstatus )
58  {
59  case _HEAPEMPTY:
60  _tmp << "OK - empty heap\n";
61  break;
62  case _HEAPEND:
63  _tmp << "OK - end of heap\n";
64  break;
65  case _HEAPBADPTR:
66  _tmp << "ERROR - bad pointer to heap\n";
67  break;
68  case _HEAPBADBEGIN:
69  _tmp << "ERROR - bad start of heap\n";
70  break;
71  case _HEAPBADNODE:
72  _tmp << "ERROR - bad node in heap\n";
73  break;
74  }
75  INFO_PRINT << _tmp.str();
76 #endif
77 }
78 }
79 }
size_t last_bytes_used
Definition: allocd.cpp:22
void PrintAllocationData()
Definition: allocd.cpp:26
size_t last_bytes_free
Definition: allocd.cpp:24
size_t last_blocks_free
Definition: allocd.cpp:23
size_t last_blocks_used
Definition: allocd.cpp:21
#define INFO_PRINT
Definition: logfacility.h:223
Definition: berror.cpp:12