1
0
Fork 0

Codechange: do not zero pool item upon allocation any more

pull/13632/head
Rubidium 2025-02-18 21:33:09 +01:00 committed by rubidium42
parent 15dcf56dad
commit 426b03b31a
3 changed files with 6 additions and 14 deletions

View File

@ -25,7 +25,7 @@ using CargoPacketID = PoolID<uint32_t, struct CargoPacketIDTag, 0xFFF000, 0xFFFF
struct CargoPacket;
/** Type of the pool for cargo packets for a little over 16 million packets. */
using CargoPacketPool = Pool<CargoPacket, CargoPacketID, 1024, PoolType::Normal, true, false>;
using CargoPacketPool = Pool<CargoPacket, CargoPacketID, 1024, PoolType::Normal, true>;
/** The actual pool with cargo packets. */
extern CargoPacketPool _cargopacket_pool;

View File

@ -23,9 +23,9 @@
* @param type The return type of the method.
*/
#define DEFINE_POOL_METHOD(type) \
template <class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type, bool Tcache, bool Tzero> \
template <class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type, bool Tcache> \
requires std::is_base_of_v<PoolIDBase, Tindex> \
type Pool<Titem, Tindex, Tgrowth_step, Tpool_type, Tcache, Tzero>
type Pool<Titem, Tindex, Tgrowth_step, Tpool_type, Tcache>
/**
* Create a clean pool.
@ -113,13 +113,6 @@ DEFINE_POOL_METHOD(inline void *)::AllocateItem(size_t size, size_t index)
assert(sizeof(Titem) == size);
item = reinterpret_cast<Titem *>(this->alloc_cache);
this->alloc_cache = this->alloc_cache->next;
if (Tzero) {
/* Explicitly casting to (void *) prevents a clang warning -
* we are actually memsetting a (not-yet-constructed) object */
memset(static_cast<void *>(item), 0, sizeof(Titem));
}
} else if (Tzero) {
item = reinterpret_cast<Titem *>(CallocT<uint8_t>(size));
} else {
item = reinterpret_cast<Titem *>(MallocT<uint8_t>(size));
}

View File

@ -126,10 +126,9 @@ private:
* @tparam Tgrowth_step Size of growths; if the pool is full increase the size by this amount
* @tparam Tpool_type Type of this pool
* @tparam Tcache Whether to perform 'alloc' caching, i.e. don't actually free/malloc just reuse the memory
* @tparam Tzero Whether to zero the memory
* @warning when Tcache is enabled *all* instances of this pool's item must be of the same size.
*/
template <class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type = PoolType::Normal, bool Tcache = false, bool Tzero = true>
template <class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type = PoolType::Normal, bool Tcache = false>
requires std::is_base_of_v<PoolIDBase, Tindex>
struct Pool : PoolBase {
public:
@ -282,12 +281,12 @@ public:
* Base class for all PoolItems
* @tparam Tpool The pool this item is going to be part of
*/
template <struct Pool<Titem, Tindex, Tgrowth_step, Tpool_type, Tcache, Tzero> *Tpool>
template <struct Pool<Titem, Tindex, Tgrowth_step, Tpool_type, Tcache> *Tpool>
struct PoolItem {
Tindex index; ///< Index of this pool item
/** Type of the pool this item is going to be part of */
typedef struct Pool<Titem, Tindex, Tgrowth_step, Tpool_type, Tcache, Tzero> Pool;
typedef struct Pool<Titem, Tindex, Tgrowth_step, Tpool_type, Tcache> Pool;
/**
* Allocates space for new Titem