Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/theodesp/go-object-pool
Simple and efficient implementation of a generic Object Pool in Go
https://github.com/theodesp/go-object-pool
design-patterns golang object-pool resource-pool
Last synced: about 1 month ago
JSON representation
Simple and efficient implementation of a generic Object Pool in Go
- Host: GitHub
- URL: https://github.com/theodesp/go-object-pool
- Owner: theodesp
- License: mit
- Created: 2018-01-01T11:48:14.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-01T22:42:54.000Z (almost 7 years ago)
- Last Synced: 2024-10-03T07:23:36.673Z (about 2 months ago)
- Topics: design-patterns, golang, object-pool, resource-pool
- Language: Go
- Size: 5.86 KB
- Stars: 12
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING
- License: LICENSE
Awesome Lists containing this project
README
The object pool pattern is a software **creational
design pattern** that uses a set of initialized objects
kept ready to use – a "pool" – rather than allocating and
destroying them on demand.
A client of the pool will request an object from the pool
and perform operations on the returned object.
When the client has finished, it returns the object
to the pool rather than destroying it;
this can be done manually or automatically.## Installation
```bash
$ go get -u github.com/theodesp/go-object-pool
```## Usage
Provide the necessary interface implementations first and then
create the Pool```go
type ByteBufferObject struct {
buffer *bytes.Buffer
}func (b *ByteBufferObject) Reset() {
b.buffer.Reset()
}type ByteBufferFactory struct{}
func (f ByteBufferFactory) Create() (PooledObject, error) {
return &ByteBufferObject{
buffer: bytes.NewBuffer(make([]byte, 1024)),
}, nil
}factory := &ByteBufferFactory{}
pool := NewFixedPool(16, factory)obj, _ := pool.Get()
pool.Return(obj)
```## LICENCE
Copyright © 2017 Theo Despoudis MIT license