libtrbase
1.0.2
Web server and task management solution.
|
#include <stdlib.h>
#include <sys/types.h>
Go to the source code of this file.
Data Structures | |
struct | memSegment |
Macros | |
#define | TR_MEM_FREE(seg) (TR_free((void **)&(seg))) |
#define | LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n |
Functions | |
int | TR_bitwidth (size_t value) |
struct memSegment * | _getMemInfo (void *mem) |
size_t | TR_getSize (void *mem) |
size_t | TR_getUsableSize (void *mem) |
int | TR_getIdx (void *mem) |
void * | TR_malloc (size_t) |
void * | TR_calloc (size_t, size_t) |
void * | TR_reference (void *) |
void | TR_free (void **) |
void | TR_cleanup () |
char * | TR_strdup (const char *) |
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file memory.h.
struct memSegment |
Data Fields | ||
---|---|---|
int | idx | |
struct memSegment * | next | |
void * | ptr | |
size_t | ref_count | |
size_t | size |
#define LT | ( | n | ) | n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n |
Referenced by TR_bitwidth().
#define TR_MEM_FREE | ( | seg | ) | (TR_free((void **)&(seg))) |
Definition at line 26 of file memory.h.
Referenced by sizedDataDtor(), TR_loggerLog(), and TR_sizedDataSetData().
struct memSegment* _getMemInfo | ( | void * | mem | ) |
Definition at line 84 of file memory.h.
|
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 ** | ) |
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 | ) |
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 * | ) |
char* TR_strdup | ( | const char * | ) |
Definition at line 292 of file memory.c.
References TR_malloc().