Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Pangea-Agent
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gavin-Group
Pangea-Agent
Commits
004fa6bb
Commit
004fa6bb
authored
Dec 21, 2025
by
ligaowei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ObjectPoolService for unified object pooling management
parent
b5a64d8a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
+53
-0
ObjectPoolService.ts
frontend/src/services/ObjectPoolService.ts
+53
-0
No files found.
frontend/src/services/ObjectPoolService.ts
0 → 100644
View file @
004fa6bb
// 对象池服务
export
class
ObjectPoolService
<
T
>
{
private
pool
:
T
[]
=
[];
private
factory
:
()
=>
T
;
private
resetter
?:
(
obj
:
T
)
=>
void
;
private
maxSize
:
number
;
constructor
(
factory
:
()
=>
T
,
resetter
?:
(
obj
:
T
)
=>
void
,
maxSize
:
number
=
100
)
{
this
.
factory
=
factory
;
this
.
resetter
=
resetter
;
this
.
maxSize
=
maxSize
;
}
/**
* 从对象池获取对象
* @returns 对象实例
*/
acquire
():
T
{
if
(
this
.
pool
.
length
>
0
)
{
return
this
.
pool
.
pop
()
!
;
}
return
this
.
factory
();
}
/**
* 将对象归还到对象池
* @param obj 对象实例
*/
release
(
obj
:
T
):
void
{
if
(
this
.
resetter
)
{
this
.
resetter
(
obj
);
}
if
(
this
.
pool
.
length
<
this
.
maxSize
)
{
this
.
pool
.
push
(
obj
);
}
}
/**
* 清空对象池
*/
clear
():
void
{
this
.
pool
=
[];
}
/**
* 获取对象池当前大小
* @returns 对象池大小
*/
size
():
number
{
return
this
.
pool
.
length
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment