Lolly 1.4.27
Loading...
Searching...
No Matches
je_malloc.cpp
Go to the documentation of this file.
1
2/******************************************************************************
3 * MODULE : Fast memory allocation using jemalloc
4 * DESCRIPTION:
5 * COPYRIGHT : (C) 2023-2024 jingkaimori
6 *******************************************************************************
7 * This software falls under the GNU general public license version 3 or later.
8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ******************************************************************************/
11
12#include "assert.h"
13#include "fast_alloc.hpp"
14#include "tm_ostream.hpp"
15#include <jemalloc/jemalloc.h>
16
17int mem_used ();
18
19/*****************************************************************************/
20// General purpose fast allocation routines
21/*****************************************************************************/
22
23void*
24safe_malloc (size_t sz) {
25 void* ptr= malloc (sz);
26
27 if (ptr == NULL) {
28 cerr << "Fatal error: out of memory\n";
29 abort ();
30 }
31 return ptr;
32}
33
34void*
35fast_alloc (size_t sz) {
36 return safe_malloc (sz);
37}
38
39void
40fast_free (void* ptr, size_t sz) {
41 free (ptr);
42}
43
44void*
45fast_realloc (void* ptr, size_t, size_t new_size) {
46 void* new_ptr= realloc (ptr, new_size);
47
48 if (new_ptr == NULL) {
49 cerr << "Fatal error: out of memory\n";
50 abort ();
51 }
52 return new_ptr;
53}
54
55void*
56fast_new (size_t s) {
57 return safe_malloc (s);
58}
59
60void
62 free (ptr);
63}
64
65void
67
68/******************************************************************************
69 * Statistics
70 ******************************************************************************/
71
72int
74 cerr << "memory statistics is NOT IMPLEMENTED\n";
75 return 0;
76}
77
78void
80 cout << "\n------- (NOT IMPLEMENTED) memory statistics -------\n";
81}
The list class represents a linked list.
Definition list.hpp:48
void mem_info()
Definition je_malloc.cpp:79
void fast_delete(void *ptr)
Definition je_malloc.cpp:61
void fast_free(void *ptr, size_t sz)
Definition je_malloc.cpp:40
int mem_used()
Definition je_malloc.cpp:73
void * fast_new(size_t s)
Definition je_malloc.cpp:56
void * fast_alloc(size_t sz)
Definition je_malloc.cpp:35
void mem_init()
Definition je_malloc.cpp:66
void * safe_malloc(size_t sz)
Definition je_malloc.cpp:24
void * fast_realloc(void *ptr, size_t, size_t new_size)
Definition je_malloc.cpp:45
tm_ostream & cerr
tm_ostream & cout