libtrbase
1.0.2
Web server and task management solution.
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <search.h>
#include <unistd.h>
#include <stdint.h>
#include "tr/memory.h"
Go to the source code of this file.
Macros | |
#define | _GNU_SOURCE |
#define | MIN_BITS 8 |
Functions | |
int | TR_bitwidth (size_t) |
size_t | TR_getSize (void *) |
size_t | TR_getUsableSize (void *) |
int | TR_getIdx (void *) |
static struct memSegment * | newElement (size_t size, int idx) |
void * | TR_reference (void *mem) |
void * | TR_malloc (size_t size) |
void * | TR_calloc (size_t nmemb, size_t size) |
void | TR_free (void **mem) |
void | TR_cleanup () |
char * | TR_strdup (const char *src) |
#define MIN_BITS 8 |
Referenced by TR_malloc().
|
static |
Definition at line 80 of file memory.c.
References memSegment::idx, memSegment::next, memSegment::ptr, memSegment::ref_count, and memSegment::size.
Referenced by TR_malloc().
|
inline |
I found this at stanford.edu: https://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup
Really cool way of dealing with this. The oneat stanford.edu is slightly different as ist deals only with 32bit values. I need a 64bit version because on a 64bit system size_t is also 64bit and thus it is possible to allocate that much amount of memory theoretically.
Definition at line 52 of file memory.h.
References LT.
Referenced by TR_malloc().
void* TR_calloc | ( | size_t | nmemb, |
size_t | size | ||
) |
this is a really memory wasting solution....just to be able to use calloc, which might be faster then malloc/memset solution.
Maybe this is a bad idea, as we need to memset the buffer anyway if it comes from our tree, which hopefully should be the majority of cases.
Definition at line 242 of file memory.c.
References memSegment::size, TR_getUsableSize(), and TR_malloc().
void TR_cleanup | ( | ) |
void TR_free | ( | void ** | mem | ) |
Definition at line 253 of file memory.c.
References memSegment::idx, and memSegment::ref_count.
|
inline |
|
inline |
Definition at line 95 of file memory.h.
References memSegment::size.
Referenced by TR_getUsableSize(), and TR_sizedDataSetData().
|
inline |
Definition at line 105 of file memory.h.
References memSegment::size, and TR_getSize().
Referenced by TR_calloc().
void* TR_malloc | ( | size_t | size | ) |
Definition at line 178 of file memory.c.
References memSegment::idx, MIN_BITS, newElement(), memSegment::ptr, and TR_bitwidth().
Referenced by sizedDataCtor(), TR_calloc(), TR_loggerLog(), TR_sizedDataSetData(), and TR_strdup().
void* TR_reference | ( | void * | mem | ) |
char* TR_strdup | ( | const char * | src | ) |
Definition at line 292 of file memory.c.
References TR_malloc().