Skip to content

Commit

Permalink
Bugfix: HeapUsed() still sometimes did not return on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausMu committed Dec 23, 2024
1 parent 79fb23a commit ae9d9ee
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
// returns used heap size in bytes or negative if heap is corrupted.
// It seems the while loop sometimes never ends. Reason unknown.
// If this happens, stop after 200 iterations and return the fake numer 800000, as we are doing in Linux.
// Update: and even with this fallback sometimes the function does not return. Weird. So simply return 800000.
long HeapUsed()
{
return 800000;

_HEAPINFO info = { 0, 0, 0 };
long used = 0;
int rc;

int loopCounter = 0;
while (((rc=_heapwalk(&info)) == _HEAPOK) && (loopCounter < 100))
while (((rc=_heapwalk(&info)) == _HEAPOK) && (loopCounter < 200))
{
if (info._useflag == _USEDENTRY)
used += info._size;
Expand All @@ -25,7 +28,7 @@ long HeapUsed()
if (rc != _HEAPEND && rc != _HEAPEMPTY)
used = (used?-used:-1);

if (loopCounter <= 100) {
if (loopCounter <= 200) {
return used;
} else {
return 800000;
Expand Down

0 comments on commit ae9d9ee

Please sign in to comment.