Keep track of dynamic buffer allocations.

This commit is contained in:
Dianne Skoll
2025-12-31 17:28:25 -05:00
parent d4ed89f5ba
commit 0ee5efa4df
4 changed files with 24 additions and 0 deletions
+12
View File
@@ -17,6 +17,15 @@
#include <string.h>
#include <stdlib.h>
static size_t NumMallocs = 0;
static size_t BytesMalloced = 0;
void DBufGetMallocStats(size_t *num_mallocs, size_t *bytes_malloced)
{
*num_mallocs = NumMallocs;
*bytes_malloced = BytesMalloced;
}
/**********************************************************************
%FUNCTION: DBufMakeRoom
%ARGUMENTS:
@@ -45,6 +54,9 @@ static int DBufMakeRoom(DynamicBuffer *dbuf, size_t n)
buf = malloc(size);
if (!buf) return E_NO_MEM;
NumMallocs++;
BytesMalloced += size;
/* Copy contents */
strcpy(buf, dbuf->buffer);