Thread: ZO_ObjectPool
View Single Post
03/01/14, 06:34 PM   #4
Pawkette
 
Pawkette's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 20
Precisely that, the real concept behind ZO_ObjectPool is that you have a number of generic objects that you don't want to instantiate any time they're needed. So, ZO_ObjectPool will create an object, and when you release that object it goes back into a pool - never garbage collected. The next time you need an object, it asks that pool if any are sitting around unused and gives you that unused object instead of instantiating a new one.

It's a lot of fancy code to basically represent:

Lua Code:
  1. local in_use = {}
  2. local unused = {}
  3.  
  4. function GetNew()
  5.   if ( #unused ) then
  6.     return unused[ 1 ]
  7.   else
  8.      -- create new object
  9.   end
  10. end
  11.  
  12. function Release( object )
  13.   --remove from in_use
  14.   table.insert( unused, object )
  15. end
  16.  
  17. local obj = GetNew()
  18. table.insert( in_use, obj )
  19. obj:DoStuff()
  20. Release( obj )

Last edited by Pawkette : 03/01/14 at 06:37 PM.
  Reply With Quote