I want to know if ArrayList
represent an Object Pool Pattern. It has an array of Object
inside. And all objects of ArrayList
can frequently be reused.
Asked
Active
Viewed 1,115 times
-2

naXa stands with Ukraine
- 35,493
- 19
- 190
- 259

Arkasha
- 117
- 2
- 12
-
3You can use a `List` to implement a pool so that it will be the backing storage in you `ObjectPool` class, but the `List` itself definitely is not an implementation of the Object pool pattern. – Petr Janeček Apr 29 '14 at 15:26
-
2I don't think I understand your question... – Giovanni Botta Apr 29 '14 at 15:28
-
If anything, a Queue would make a better base for implementing a pool. – Apr 29 '14 at 15:37
-
@Arkadiy, please, explain why. – naXa stands with Ukraine Apr 29 '14 at 15:50
-
offer() and poll() I think are closer to object pool semantics than add() and remove(0). – Apr 29 '14 at 15:56
1 Answers
2
ArrayList
can be a pool container, but it isn't an object pool itself. It needs some algorithmic support to implement caching.
If you, for example, keep track of the head and the tail of the array instead of adding/removing objects to/from the array as it should be, you'll get some kind of manual memory management. Your objects won't be deleted and will probably be reused. Thereat you'll have the right to say that your program uses The object pool pattern.

naXa stands with Ukraine
- 35,493
- 19
- 190
- 259