Small cleanups for PooledList and PagedAllocator.

This commit is contained in:
Relintai 2023-01-15 18:00:34 +01:00
parent 698c2e01f0
commit 389052c51a
2 changed files with 10 additions and 6 deletions

View File

@ -34,8 +34,6 @@
#include "core/os/spin_lock.h"
#include "core/typedefs.h"
#include <type_traits>
template <class T, bool thread_safe = false>
class PagedAllocator {
T **page_pool = nullptr;
@ -91,7 +89,7 @@ public:
}
void reset(bool p_allow_unfreed = false) {
if (!p_allow_unfreed || !std::is_trivially_destructible<T>::value) {
if (!p_allow_unfreed || !__has_trivial_destructor(T)) {
ERR_FAIL_COND(allocs_available < pages_allocated * page_size);
}
if (pages_allocated) {
@ -119,7 +117,9 @@ public:
page_shift = get_shift_from_power_of_2(page_size);
}
PagedAllocator(uint32_t p_page_size = 4096) { // power of 2 recommended because of alignment with OS page sizes. Even if element is bigger, its still a multiple and get rounded amount of pages
// Power of 2 recommended because of alignment with OS page sizes.
// Even if element is bigger, its still a multiple and get rounded amount of pages
PagedAllocator(uint32_t p_page_size = 4096) {
configure(p_page_size);
}

View File

@ -1,3 +1,7 @@
#ifndef POOLED_LIST_H
#define POOLED_LIST_H
/*************************************************************************/
/* pooled_list.h */
/*************************************************************************/
@ -28,8 +32,6 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#pragma once
// Simple template to provide a pool with O(1) allocate and free.
// The freelist could alternatively be a linked list placed within the unused elements
// to use less memory, however a separate freelist is probably more cache friendly.
@ -206,3 +208,5 @@ private:
LocalVector<U, U> _active_map;
LocalVector<U, U> _active_list;
};
#endif