src/oldpool_func.h
changeset 10316 6878402fa6e5
parent 9343 c30fd350dd8c
child 10429 1b99254f9607
equal deleted inserted replaced
10315:b5a6fb206640 10316:6878402fa6e5
    29 	if (Tpool->AddBlockToPool()) return AllocateRaw(first);
    29 	if (Tpool->AddBlockToPool()) return AllocateRaw(first);
    30 
    30 
    31 	return NULL;
    31 	return NULL;
    32 }
    32 }
    33 
    33 
       
    34 /**
       
    35  * Check whether we can allocate an item in this pool. This to prevent the
       
    36  * need to actually construct the object and then destructing it again,
       
    37  * which could be *very* costly.
       
    38  * @return true if and only if at least ONE item can be allocated.
       
    39  */
       
    40 template<typename T, typename Tid, OldMemoryPool<T> *Tpool> bool PoolItem<T, Tid, Tpool>::CanAllocateItem()
       
    41 {
       
    42 	uint last_minus_one = Tpool->GetSize() - 1;
       
    43 
       
    44 	for (T *t = Tpool->Get(Tpool->first_free_index); t != NULL; t = (t->index < last_minus_one) ? Tpool->Get(t->index + 1U) : NULL) {
       
    45 		if (!t->IsValid()) return true;
       
    46 		Tpool->first_free_index = t->index;
       
    47 	}
       
    48 
       
    49 	/* Check if we can add a block to the pool */
       
    50 	if (Tpool->AddBlockToPool()) return CanAllocateItem();
       
    51 
       
    52 	return false;
       
    53 }
       
    54 
    34 #endif /* OLDPOOL_FUNC_H */
    55 #endif /* OLDPOOL_FUNC_H */