{"id":26766584,"url":"https://github.com/xenonbyte/objectpool","last_synced_at":"2025-04-15T13:43:17.801Z","repository":{"id":266297619,"uuid":"897914549","full_name":"xenonbyte/objectpool","owner":"xenonbyte","description":"Object reuse pool suitable for objects that are frequently created and destroyed","archived":false,"fork":false,"pushed_at":"2025-02-04T16:52:47.000Z","size":89,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T20:44:44.348Z","etag":null,"topics":["kotlin","object-reuse","objectpool"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xenonbyte.png","metadata":{"files":{"readme":"README-zh.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-03T13:14:48.000Z","updated_at":"2025-03-18T18:48:56.000Z","dependencies_parsed_at":"2024-12-30T17:35:05.047Z","dependency_job_id":"eda90ebf-7832-4c97-a1c4-ac121593b7a1","html_url":"https://github.com/xenonbyte/objectpool","commit_stats":null,"previous_names":["xubo90/objectpool","xenonbyte/objectpool"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xenonbyte%2Fobjectpool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xenonbyte%2Fobjectpool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xenonbyte%2Fobjectpool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xenonbyte%2Fobjectpool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xenonbyte","download_url":"https://codeload.github.com/xenonbyte/objectpool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249081997,"owners_count":21209792,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kotlin","object-reuse","objectpool"],"created_at":"2025-03-28T20:39:33.352Z","updated_at":"2025-04-15T13:43:17.781Z","avatar_url":"https://github.com/xenonbyte.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ObjectPool\n\n适用于对象频繁创建和销毁的对象复用池；当复用池中存在实例则复用该实例，如果不存在则创建新的实例\n\n## 使用\n\n### 创建全局对象复用池\n\n```kotlin\nval pool = ObjectPoolProvider.global().get(Person::class.java, object : ObjectFactory\u003cPerson\u003e {\n    override fun create(vararg args: Any?): Person {\n        val name = args[0] as String\n        val age = args[1] as Int\n        return Person(name, age)\n    }\n\n    override fun reuse(instance: Person, vararg args: Any?) {\n        val name = args[0] as String\n        val age = args[1] as Int\n        instance.name = name\n        instance.age = age\n    }\n\n})\n```\n\n### 使用`ObjectPoolStoreOwner`创建对象复用池\n\n```kotlin\nval store = ObjectPoolStore()\nval storeOwner = object : ObjectPoolStoreOwner {\n    override val store: ObjectPoolStore\n        get() = store\n\n}\nval pool = ObjectPoolProvider.create(storeOwner).get(Person::class.java, object : ObjectFactory\u003cPerson\u003e {\n    override fun create(vararg args: Any?): Person {\n        val name = args[0] as String\n        val age = args[1] as Int\n        return Person(name, age)\n    }\n\n    override fun reuse(instance: Person, vararg args: Any?) {\n        val name = args[0] as String\n        val age = args[1] as Int\n        instance.name = name\n        instance.age = age\n    }\n\n})\n```\n\n### 获取对象\n\n从对象复用池获取对象,如果复用池存在实例，复用该实例；如果不存在则创建新的实例\n\n```kotlin\nval person = pool.obtain(\"Andy\", 16);\n```\n\n### 回收对象\n\n对象复用池回收对象，方便复用\n\n```kotlin\npool.recycle(person)\n```\n\n### 实现`Reusable`接口\n\n复用对象需实现`Reusable`接口\n\n```kotlin\nclass Person(var name: String, var age: Int) : Reusable\n```\n\n## Download\n\n```groovy\nrepositories {\n    maven { url 'https://jitpack.io' }\n}\n\ndependencies {\n    implementation 'com.github.xenonbyte:ObjectPool:1.0.0'\n}\n```\n\n## License\n\nCopyright [2024] [xubo]\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxenonbyte%2Fobjectpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxenonbyte%2Fobjectpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxenonbyte%2Fobjectpool/lists"}