Start writing a function to compute the in-memory size of an object.

This commit is contained in:
Jordan Bancino 2022-11-06 00:47:17 +00:00
parent 45951569dd
commit 37ee7700f4

View file

@ -24,6 +24,7 @@
#include <Db.h>
#include <Memory.h>
#include <Json.h>
#include <pthread.h>
@ -46,6 +47,45 @@ struct DbRef
char *file;
};
static ssize_t
DbComputeSize(HashMap *json)
{
char *key;
JsonValue *val;
MemoryInfo *a;
size_t total;
if (!json)
{
return -1;
}
total = 0;
a = MemoryInfoGet(json);
if (a)
{
total += MemoryInfoGetSize(a);
}
while (HashMapIterate(json, &key, (void **) &val))
{
a = MemoryInfoGet(key);
if (a)
{
total += MemoryInfoGetSize(a);
}
a = MemoryInfoGet(val);
if (a)
{
total += MemoryInfoGetSize(a);
}
}
return total;
}
Db *
DbOpen(const char *dir, size_t cache)
{