std.objectpool Package
Function Description
The objectpool package provides functions for object cache and reuse.
In object-oriented languages, the application and release of objects are complex and time-consuming, which may become the performance bottleneck of applications. The application and release of Cangjie objects also face the same problem. The object pool improves program performance through caching and reusing objects to reduce object application and release.
This package ObjectPool
class is used to cache and reuse objects of a specified type. The put
method can be called to put used objects into the object pool cache, and the get
method can be called to obtain the objects to be used from the object pool cache.
In addition, to reduce contention and further improve object access efficiency, ObjectPool
object access is performed in different arrays based on a current Cangjie thread id
.
Note:
1. During
ObjectPool
implementation, access is performed based on a Cangjie threadid
. As a result, when an object is obtained and stored by different Cangjie threads, it is difficult to obtain a stored object. Therefore, the object pool should be used in scenarios in which an object is obtained and stored by the same Cangjie thread.2. Automatic capacity reduction is not supported.
API List
Class
Name | Description |
---|---|
ObjectPool | Provides a concurrent-secure object cache type, which can store objects that have been allocated memory but are not in use. |