SWC-DB
v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Malloc.cc
Go to the documentation of this file.
1
/*
2
* SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3
* License details at <https://github.com/kashirin-alex/swc-db/#license>
4
*/
5
6
#include "
swcdb/core/Compat.h
"
7
8
9
10
namespace
SWC
{
11
12
13
SWC_CAN_INLINE
SWC_MALLOC_FUNC
14
void
*
Memory::allocate
(
const
size_t
sz) noexcept {
15
for
(;;) {
16
void
* ptr = malloc(sz);
17
if
(ptr || !sz) {
// !sz, nullptr for zero bytes
18
//printf(
19
// "alloc sz=" SWC_FMT_LU " p=" SWC_FMT_LU "\n",
20
// sz, uint64_t(ptr)
21
//);
22
return
ptr;
23
}
24
printf(
25
"Bad-alloc sz="
SWC_FMT_LU
"\n"
,
26
sz
27
);
28
std::this_thread::sleep_for(std::chrono::nanoseconds(sz));
29
}
30
}
31
32
SWC_CAN_INLINE
SWC_MALLOC_FUNC
33
void
*
Memory::allocate
(
const
size_t
sz, std::align_val_t al) noexcept {
34
for
(;;) {
35
void
* ptr = aligned_alloc(
size_t
(al), sz);
36
if
(ptr || !sz) {
// !sz, nullptr for zero bytes
37
//printf(
38
// "alloc sz=" SWC_FMT_LU " al=" SWC_FMT_LU " p=" SWC_FMT_LU "\n",
39
// sz, uint64_t(al), uint64_t(ptr)
40
//);
41
return
ptr;
42
}
43
printf(
44
"Bad-alloc sz="
SWC_FMT_LU
" al="
SWC_FMT_LU
"\n"
,
45
sz, uint64_t(al)
46
);
47
std::this_thread::sleep_for(std::chrono::nanoseconds(sz));
48
}
49
}
50
51
52
SWC_CAN_INLINE
53
void
Memory::free
(
void
* ptr) noexcept {
54
//printf(
55
// "free p=" SWC_FMT_LU "\n",
56
// uint64_t(ptr)
57
//);
58
std::free(ptr);
59
}
60
61
62
}
SWC::Memory::free
static void free(void *ptr) noexcept
Definition:
Malloc.cc:53
SWC::Memory::allocate
static SWC_MALLOC_FUNC void * allocate(const size_t sz) noexcept
Definition:
Malloc.cc:14
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition:
Compat.h:102
SWC
The SWC-DB C++ namespace 'SWC'.
Definition:
main.cc:12
Compat.h
SWC_FMT_LU
#define SWC_FMT_LU
Definition:
Compat.h:98
SWC_MALLOC_FUNC
#define SWC_MALLOC_FUNC
Definition:
Compat.h:109
lib
swcdb
core
Malloc.cc
Generated on Sat Jun 3 2023 18:00:08 for SWC-DB by
1.8.20