-- Allocate works similarly to Pull, except it tries to reuse objects that exist in the specified bin.
-- This removes the need to recycle every object during every frame.


function recyclingBin:Allocate(objectType,needed,bin)
	local allocation = {}
	local allocated = 0
	for _,v in pairs(bin:GetChildren()) do
		if v:IsA(objectType) then
			allocated = allocated + 1
			if allocated > needed then
				self:Recycle(v)
			else
				allocation[allocated] = v
			end
		end
	end
	while allocated < needed do
		allocated = allocated + 1
		allocation[allocated] = self:Pull(objectType,bin)
	end
	return allocation
end

return recyclingBin
