treebird/src/memory.c
nekobit ded0b83151 3rd clause
FossilOrigin-Name: 8766275cac121ced2142c9dee80f2c21a0337e9eb65501961807aba8fca0f252
2022-11-14 15:36:33 +00:00

57 lines
977 B
C

/*
* Treebird - Lightweight frontend for Pleroma
*
* Licensed under the BSD 3-Clause License
*/
#include <stdlib.h>
#include <malloc.h>
#include "memory.h"
#ifdef __GLIBC__
#include <malloc.h>
#endif
int tb_memory_allocated_est;
int tb_memory_allocated;
int tb_memory_free;
int tb_memory_times_allocated;
int tb_memory_times_freed;
#ifdef __GLIBC__
void propagate_memory()
{
struct mallinfo2 inf = mallinfo2();
tb_memory_free = inf.fordblks;
tb_memory_allocated = inf.uordblks;
}
#endif // __GLIBC__
void* tb_malloc(size_t size)
{
tb_memory_allocated_est += size;
++tb_memory_times_allocated;
return malloc(size);
}
// Nothing....
void* tb_calloc(size_t nmemb, size_t size)
{
tb_memory_allocated_est = size * nmemb;
return calloc(nmemb, size);
}
void* tb_realloc(void* ptr, size_t size)
{
tb_memory_allocated_est = size;
return realloc(ptr, size);
}
void tb_free(void* ptr)
{
++tb_memory_times_freed;
free(ptr);
}