﷽
Design a resource pool with ease of use and safety guarantees using RAII principles to ensure:
- Stored object lifetime management
- Stored object restored to the pool
- Strict scoped checkout and checkin semantics
#include "siddiqsoft/resource_pool.hpp"
#include <memory>
class DatabaseConnection {
public:
void execute(const std::string& query) { /* ... */ }
};
int main() {
// Create a resource pool
siddiqsoft::arrp::resource_pool<std::shared_ptr<DatabaseConnection>> pool;
// Populate the pool
for (int i = 0; i < 5; ++i) {
pool.return_to_pool(std::make_shared<DatabaseConnection>());
}
// Borrow and use a resource
{
auto conn = pool.borrow_from_pool();
conn->execute("SELECT * FROM users");
// Automatically returned to pool when going out of scope
}
return 0;
}- Thread-Safe: All operations are protected by mutexes for concurrent access
- RAII Pattern: Automatic resource return via scoped_resource wrapper
- Capacity Management: Enforces maximum capacity limits to prevent unbounded growth
- FIFO Ordering: Resources retrieved from front, added to back
- Customizable Factory: Support for custom resource creation callbacks
- Diagnostic Counters: Track borrow, return, and auto-add operations
- Modern C++20: Uses only standard library features (no external dependencies)
- Type-Safe: Leverages C++20 concepts for compile-time type checking
- Move Semantics: Efficient resource transfer with perfect forwarding
- Language: C++20 minimum required for
std::jthread,std::mutex,std::recursive_mutex,std::scoped_lock,std::unique_lock - Optional:
nlohmann::jsonfor JSON serialization support - No External Dependencies: Only uses standard library features
- Platform Support: MacOS, Linux, Windows
- MacOS: Development platform
- Linux (RedHat): CI pipeline tested
- Windows: CI pipeline tested
- GCC: 10+ (Linux)
- Clang:
- AppleClang v21+
- LLVM v20+
- MSVC:
- Visual Studio 2019
- Visual Studio 2022
- Visual Studio 2026
include(FetchContent)
FetchContent_Declare(arrp
GIT_REPOSITORY https://github.com/SiddiqSoft/arrp.git
GIT_TAG main
)
FetchContent_MakeAvailable(arrp)
target_link_libraries(your_target PRIVATE arrp::arrp)nuget install SiddiqSoft.aarpSimply include the header files from include/siddiqsoft/ in your project.
For detailed documentation, see:
- Getting Started - Installation and setup guide
- Usage Guide - Detailed usage examples and best practices
- API Reference - Complete API documentation
- Examples - Real-world code examples
- Quick Reference - Quick lookup guide
- Security - Security considerations
| Component | Description | Use Case |
|---|---|---|
resource_pool<T> |
Thread-safe resource pool manager | Connection/resource management |
scoped_resource<T> |
RAII resource wrapper | Automatic resource return |
- Move Semantics: All components use move semantics for efficient resource transfer
- RAII: Proper resource management through constructors and destructors
- Thread Safety: Internal synchronization using mutexes and scoped locks
- Zero-Copy: Minimal data copying through perfect forwarding
- Type Safety: C++20 concepts ensure compile-time type checking
- Simplicity: Clean API that hides complexity of resource management
BSD 3-Clause License - See LICENSE file for details
Copyright (c) 2026, Abdulkareem Siddiq. All rights reserved.
- GitHub: https://github.com/SiddiqSoft/arrp
- NuGet: https://www.nuget.org/packages/SiddiqSoft.aarp/
- Documentation: https://siddiqsoft.github.io/arrp/