SimpleKernel 1.17.0
Loading...
Searching...
No Matches
kstd_new.cpp File Reference
#include <cstddef>
#include <new>
#include "sk_stdlib.h"
Include dependency graph for kstd_new.cpp:

Go to the source code of this file.

Functions

void * operator new (size_t size)
 
void * operator new[] (size_t size)
 
void * operator new (size_t size, size_t alignment) noexcept
 
void * operator new[] (size_t size, size_t alignment) noexcept
 
void * operator new (size_t size, std::align_val_t alignment)
 
void * operator new[] (size_t size, std::align_val_t alignment)
 
auto operator delete (void *ptr) noexcept -> void
 
auto operator delete (void *ptr, size_t) noexcept -> void
 
auto operator delete[] (void *ptr) noexcept -> void
 
auto operator delete[] (void *ptr, size_t) noexcept -> void
 
auto operator delete (void *ptr, size_t, size_t) noexcept -> void
 
auto operator delete[] (void *ptr, size_t, size_t) noexcept -> void
 
auto operator delete (void *ptr, std::align_val_t) noexcept -> void
 
auto operator delete[] (void *ptr, std::align_val_t) noexcept -> void
 
auto operator delete (void *ptr, size_t, std::align_val_t) noexcept -> void
 
auto operator delete[] (void *ptr, size_t, std::align_val_t) noexcept -> void
 

Function Documentation

◆ operator delete() [1/5]

auto operator delete ( void *  ptr) -> void
noexcept

Definition at line 68 of file kstd_new.cpp.

68 {
69 if (ptr != nullptr) {
70 free(ptr);
71 }
72}
void free(void *ptr)
Definition memory.cpp:38
Here is the call graph for this function:

◆ operator delete() [2/5]

auto operator delete ( void *  ptr,
size_t   
) -> void
noexcept

Definition at line 74 of file kstd_new.cpp.

74 {
75 if (ptr != nullptr) {
76 free(ptr);
77 }
78}
Here is the call graph for this function:

◆ operator delete() [3/5]

auto operator delete ( void *  ptr,
size_t  ,
size_t   
) -> void
noexcept

Definition at line 92 of file kstd_new.cpp.

92 {
93 if (ptr != nullptr) {
94 aligned_free(ptr);
95 }
96}
void aligned_free(void *ptr)
Definition memory.cpp:65
Here is the call graph for this function:

◆ operator delete() [4/5]

auto operator delete ( void *  ptr,
size_t  ,
std::align_val_t   
) -> void
noexcept

Definition at line 116 of file kstd_new.cpp.

116 {
117 if (ptr != nullptr) {
118 aligned_free(ptr);
119 }
120}
Here is the call graph for this function:

◆ operator delete() [5/5]

auto operator delete ( void *  ptr,
std::align_val_t   
) -> void
noexcept

Definition at line 104 of file kstd_new.cpp.

104 {
105 if (ptr != nullptr) {
106 aligned_free(ptr);
107 }
108}
Here is the call graph for this function:

◆ operator delete[]() [1/5]

auto operator delete[] ( void *  ptr) -> void
noexcept

Definition at line 80 of file kstd_new.cpp.

80 {
81 if (ptr != nullptr) {
82 free(ptr);
83 }
84}
Here is the call graph for this function:

◆ operator delete[]() [2/5]

auto operator delete[] ( void *  ptr,
size_t   
) -> void
noexcept

Definition at line 86 of file kstd_new.cpp.

86 {
87 if (ptr != nullptr) {
88 free(ptr);
89 }
90}
Here is the call graph for this function:

◆ operator delete[]() [3/5]

auto operator delete[] ( void *  ptr,
size_t  ,
size_t   
) -> void
noexcept

Definition at line 98 of file kstd_new.cpp.

98 {
99 if (ptr != nullptr) {
100 aligned_free(ptr);
101 }
102}
Here is the call graph for this function:

◆ operator delete[]() [4/5]

auto operator delete[] ( void *  ptr,
size_t  ,
std::align_val_t   
) -> void
noexcept

Definition at line 122 of file kstd_new.cpp.

122 {
123 if (ptr != nullptr) {
124 aligned_free(ptr);
125 }
126}
Here is the call graph for this function:

◆ operator delete[]() [5/5]

auto operator delete[] ( void *  ptr,
std::align_val_t   
) -> void
noexcept

Definition at line 110 of file kstd_new.cpp.

110 {
111 if (ptr != nullptr) {
112 aligned_free(ptr);
113 }
114}
Here is the call graph for this function:

◆ operator new() [1/3]

void * operator new ( size_t  size)

Definition at line 10 of file kstd_new.cpp.

10 {
11 if (size == 0) {
12 size = 1;
13 }
14 return malloc(size);
15}
void * malloc(size_t size)
Definition memory.cpp:31
Here is the call graph for this function:

◆ operator new() [2/3]

void * operator new ( size_t  size,
size_t  alignment 
)
noexcept

Definition at line 24 of file kstd_new.cpp.

24 {
25 if (size == 0) {
26 size = 1;
27 }
28
29 // 确保对齐参数是 2 的幂
30 if (alignment == 0 || (alignment & (alignment - 1)) != 0) {
31 return nullptr;
32 }
33
34 // 如果对齐要求小于等于默认对齐,使用普通 malloc
35 if (alignment <= alignof(std::max_align_t)) {
36 return malloc(size);
37 }
38
39 return aligned_alloc(alignment, size);
40}
void * aligned_alloc(size_t alignment, size_t size)
Definition memory.cpp:58
Here is the call graph for this function:

◆ operator new() [3/3]

void * operator new ( size_t  size,
std::align_val_t  alignment 
)

Definition at line 60 of file kstd_new.cpp.

60 {
61 return operator new(size, static_cast<size_t>(alignment));
62}

◆ operator new[]() [1/3]

void * operator new[] ( size_t  size)

Definition at line 17 of file kstd_new.cpp.

17 {
18 if (size == 0) {
19 size = 1;
20 }
21 return malloc(size);
22}
Here is the call graph for this function:

◆ operator new[]() [2/3]

void * operator new[] ( size_t  size,
size_t  alignment 
)
noexcept

Definition at line 42 of file kstd_new.cpp.

42 {
43 if (size == 0) {
44 size = 1;
45 }
46
47 // 确保对齐参数是 2 的幂
48 if (alignment == 0 || (alignment & (alignment - 1)) != 0) {
49 return nullptr;
50 }
51
52 // 如果对齐要求小于等于默认对齐,使用普通 malloc
53 if (alignment <= alignof(std::max_align_t)) {
54 return malloc(size);
55 }
56
57 return aligned_alloc(alignment, size);
58}
Here is the call graph for this function:

◆ operator new[]() [3/3]

void * operator new[] ( size_t  size,
std::align_val_t  alignment 
)

Definition at line 64 of file kstd_new.cpp.

64 {
65 return operator new[](size, static_cast<size_t>(alignment));
66}