Implements Malloc.
Malloc impl | Implements Malloc. |
Copyright | This program is free software. |
Files | |
C-kern/ | Header file of Malloc. |
C-kern/ | Implementation file of Malloc impl. |
malloc | |
static variables | |
s_isprepared_malloc | Remembers if prepare_malloc was called already. |
init | |
prepare_malloc | Calls functions to force allocating of system memory. |
manage | |
trimmemory_malloc | Uses GNU malloc_trim extension. |
query | |
allocatedsize_malloc impl | Uses GNU malloc_stats extension. |
test |
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 2 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.
© 2011 Jörg Seebohn
Header file of Malloc.
Implementation file of Malloc impl.
static variables | |
s_isprepared_malloc | Remembers if prepare_malloc was called already. |
init | |
prepare_malloc | Calls functions to force allocating of system memory. |
manage | |
trimmemory_malloc | Uses GNU malloc_trim extension. |
query | |
allocatedsize_malloc impl | Uses GNU malloc_stats extension. |
test |
static bool s_isprepared_malloc
Remembers if prepare_malloc was called already.
int prepare_malloc()
Calls functions to force allocating of system memory. No own malloc version is initialized: See allocatedsize_malloc for why.
Uses GNU malloc_stats extension. This functions returns internal collected statistics about memory usage so implementing a thin wrapper for malloc is not necessary. This function may be missing on some platforms. Currently it is only tested on Linux platforms.
The GNU C lib function malloc_stats writes textual information to standard err in the following form:
Arena 0: system bytes = 135168 in use bytes = 15000 Total (incl. mmap): system bytes = 135168 in use bytes = 15000 max mmap regions = 0 max mmap bytes = 0
This function redirects standard error file descriptor to a pipe and reads the content of the pipe into a buffer. It scans backwards until the third last line is reached (“in use bytes”) and then returns the converted the number at the end of the line as result.
Remembers if prepare_malloc was called already.
static bool s_isprepared_malloc
Calls functions to force allocating of system memory.
int prepare_malloc()
Uses GNU malloc_trim extension.
int trimmemory_malloc()
Returns allocated number of bytes which are not freed.
int allocatedsize_malloc( /*out*/size_t * number_of_allocated_bytes )