object-pool | - Simple object pool implementation
kandi X-RAY | object-pool Summary
kandi X-RAY | object-pool Summary
Simple object pool implementation.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of object-pool
object-pool Key Features
object-pool Examples and Code Snippets
Community Discussions
Trending Discussions on object-pool
QUESTION
I'm loading a crate in my project and this crate has a feature called object-pooling
that is not thread safe. Someone suggested I remove this functionality from the crate but I don't know how to do that. Is there a special entry that I can add to my Cargo.toml file and disables features
from dependencies?
ANSWER
Answered 2020-Sep-07 at 18:30The syntax in your CARGO.TOML is:
QUESTION
I have an object pool that holds objects in std::unique_ptr
.
The pool, like most pools, holds objects that are expensive to create, but once an object is borrowed there is no way of preventing an object with the same settings from being added to the pool so I'd like to extend it to prevent that from happening.
I see 3 options for this:
Replace
std::unique_ptr
withstd::shared_ptr
but there's no plans to have multithreaded code and this breaks the convention of ownership - the pool should not own an object just to read one of its properties.Keep a copy of a property of T with the pool in a
std::vector
, adding and removing whenstd::unique_ptr
is borrowed from and returned to the pool. Easy to implement but feels wrong as I'm duplicating data.Use a
std::vector>>
. By keeping a reference to borrowedstd::unique_ptr
I have access to its properties and I can easily prevent objects with the same settings from being created.
I'm currently trying to implement 3 but am stuck on how to add a reference to std::unique_ptr
to std::vector>>
. Is this even possible?
ANSWER
Answered 2020-Aug-27 at 08:46The reference version is just bad - because as soon as the unique_ptr is moved the reference wrap gets invalid. You'd better just store raw pointers instead. But in this case it won't know whether it is destroyed or not. You can make unique_ptr
with custom destructor that marks in the pool that the object is destroyed.
Besides, I believe you have a mess up in logic. If the pool holds unique_ptr
and must not create objects with same settings then it should own all the objects and handle raw/observer pointers to users. You only need to write a routine that checks whether the object is in-use and inaccessible currently.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install object-pool
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page