indexing description: "[ Objects that can store other objects to prevent them from being collected by the garbage collector. This is useful to avoid heavy garbagecollector cycles and save time during object creation due to the ability of a recycle mechanism. ]" date: "$Date$" revision: "$Revision$" class EM_POOL[G -> ANY create default_create end] feature -- Initialisation make(a_count: INTEGER) is -- Init require a_count_positive: count >=0 local i: INTEGER do create pool.make from i:=0 until i = count loop pool.put_first(create {G}) i:=i+1 end ensure count_correct: a_count = count end feature -- Access item: G is -- An instance of an object -- If the pool is not empty from the pool, otherwise it a new instance will be created. do if not pool.is_empty then Result := pool.first pool.remove_first else create Result end end put (an_item: G) is -- put an item into the pool do pool.put_first(an_item) end is_empty: BOOLEAN is -- Is the pool empty? do Result:=pool.is_empty end count: INTEGER is -- Number of items in the pool do Result:=pool.count end feature {NONE} -- Implementation pool: DS_LINKED_LIST[G] invariant pool_not_void: pool/=Void end