forked from lda/telodendria
Start writing a function to compute the in-memory size of an object.
This commit is contained in:
parent
45951569dd
commit
37ee7700f4
1 changed files with 40 additions and 0 deletions
40
src/Db.c
40
src/Db.c
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue