Skip to content

Commit 2ad18e5

Browse files
committed
Release 0.1.1: change allocate_object to allocate; change free_object to free
1 parent 09f60a1 commit 2ad18e5

File tree

7 files changed

+75
-68
lines changed

7 files changed

+75
-68
lines changed

CHANGELOG

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [0.1.0] - 2025-01-23
8+
## [0.1.1] - 2025-11-12
9+
10+
### Changed function signitures
11+
- Changed allocate_object() to allocate()
12+
- Changed free_object() to free()
13+
14+
## [0.1.0] - 2025-10-23
915

1016
### Added
1117
- Initial release of slick_object_pool
@@ -27,8 +33,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2733

2834
### Features
2935
- `ObjectPool<T>` class template for type-safe object pooling
30-
- `allocate_object()` method for O(1) object allocation
31-
- `free_object()` method for O(1) object deallocation
36+
- `allocate()` method for O(1) object allocation
37+
- `free()` method for O(1) object deallocation
3238
- `size()` method to query pool capacity
3339
- Namespace: `slick::ObjectPool<T>`
3440
- Include path: `<slick/object_pool.h>`

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.25)
22

3-
set(BUILD_VERSION 0.1.0)
3+
set(BUILD_VERSION 0.1.1)
44
project(slick_object_pool VERSION ${BUILD_VERSION} LANGUAGES CXX)
55

66
set(CMAKE_CXX_STANDARD 20)

DOCUMENTATION.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ Comprehensive documentation covering:
7373
- Pool size query
7474
- Power-of-2 note
7575

76-
2. **T* allocate_object()**
76+
2. **T* allocate()**
7777
- Comprehensive documentation
7878
- Behavior under different conditions
7979
- Performance characteristics
8080
- Thread safety guarantees
8181
- Usage examples
8282
- Important warnings
8383

84-
3. **void free_object(T* obj)**
84+
3. **void free(T* obj)**
8585
- Dual behavior (pool vs heap)
8686
- Automatic detection mechanism
8787
- Performance notes
@@ -219,7 +219,7 @@ All member variables are documented with inline comments (`///`):
219219

220220
Focus on:
221221
- Constructor documentation
222-
- `allocate_object()` and `free_object()` methods
222+
- `allocate()` and `free()` methods
223223
- Thread safety guarantees
224224
- Code examples
225225
- Warnings and notes
@@ -270,15 +270,15 @@ Full documentation including:
270270
* @par Example
271271
* @code
272272
* slick::ObjectPool<MyStruct> pool(1024);
273-
* MyStruct* obj = pool.allocate_object();
273+
* MyStruct* obj = pool.allocate();
274274
* obj->field = value;
275-
* pool.free_object(obj);
275+
* pool.free(obj);
276276
* @endcode
277277
*
278-
* @note Must be paired with free_object() to avoid memory leaks
278+
* @note Must be paired with free() to avoid memory leaks
279279
* @note Returned object is NOT automatically initialized
280280
*/
281-
T* allocate_object();
281+
T* allocate();
282282
```
283283

284284
### Key Elements

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ int main() {
9494
slick::ObjectPool<MyObject> pool(1024);
9595

9696
// Allocate object from pool
97-
MyObject* obj = pool.allocate_object();
97+
MyObject* obj = pool.allocate();
9898
obj->id = 42;
9999
obj->value = 3.14;
100100

101101
// Return object to pool
102-
pool.free_object(obj);
102+
pool.free(obj);
103103

104104
return 0;
105105
}
@@ -170,15 +170,15 @@ int main() {
170170
slick::ObjectPool<Message> pool(512);
171171

172172
// Allocate from pool
173-
Message* msg = pool.allocate_object();
173+
Message* msg = pool.allocate();
174174
msg->id = 1;
175175
std::strcpy(msg->data, "Hello, World!");
176176

177177
// Use the object...
178178
std::cout << "Message: " << msg->data << std::endl;
179179

180180
// Return to pool when done
181-
pool.free_object(msg);
181+
pool.free(msg);
182182

183183
return 0;
184184
}
@@ -199,14 +199,14 @@ struct WorkItem {
199199
void worker_thread(slick::ObjectPool<WorkItem>& pool, int thread_id) {
200200
for (int i = 0; i < 10000; ++i) {
201201
// Allocate from pool (lock-free)
202-
WorkItem* item = pool.allocate_object();
202+
WorkItem* item = pool.allocate();
203203
204204
// Do work
205205
item->task_id = thread_id * 10000 + i;
206206
process_work(*item);
207207
208208
// Return to pool (lock-free)
209-
pool.free_object(item);
209+
pool.free(item);
210210
}
211211
}
212212
@@ -235,8 +235,8 @@ int main() {
235235

236236
The pool uses atomic compare-and-swap (CAS) operations to coordinate multiple producers and consumers without locks:
237237

238-
- **Producers** (threads calling `allocate_object()`) atomically reserve slots from the pool
239-
- **Consumers** (threads calling `free_object()`) atomically return objects to the pool
238+
- **Producers** (threads calling `allocate()`) atomically reserve slots from the pool
239+
- **Consumers** (threads calling `free()`) atomically return objects to the pool
240240
- **Ring buffer** wrapping is handled atomically without blocking
241241
- **No spinlocks, no mutexes** - truly wait-free for successful operations
242242

@@ -315,13 +315,13 @@ ObjectPool(uint32_t size);
315315
316316
```cpp
317317
// Allocate an object from the pool
318-
T* allocate_object();
318+
T* allocate();
319319
```
320320
Returns a pointer to an object from the pool. If pool is exhausted, allocates a new object from heap.
321321

322322
```cpp
323323
// Return an object to the pool
324-
void free_object(T* obj);
324+
void free(T* obj);
325325
```
326326
Returns an object to the pool if it belongs to the pool, otherwise deletes it.
327327
@@ -454,8 +454,8 @@ sudo cmake --install .
454454

455455
### Guarantees
456456

457-
-**Multiple producers** can call `allocate_object()` concurrently
458-
-**Multiple consumers** can call `free_object()` concurrently
457+
-**Multiple producers** can call `allocate()` concurrently
458+
-**Multiple consumers** can call `free()` concurrently
459459
-**Mixed operations** (allocate + free) are safe
460460
-**reset()** is NOT thread-safe (use when no other threads are active)
461461

@@ -488,11 +488,11 @@ slick::ObjectPool<T> pool(1000);
488488
### Pool Exhaustion Handling
489489
490490
```cpp
491-
// When pool is exhausted, allocate_object() allocates from heap
492-
T* obj = pool.allocate_object(); // May return heap-allocated object
491+
// When pool is exhausted, allocate() allocates from heap
492+
T* obj = pool.allocate(); // May return heap-allocated object
493493
494494
// free_object() detects and handles both cases
495-
pool.free_object(obj); // Works for pool or heap objects
495+
pool.free(obj); // Works for pool or heap objects
496496
```
497497

498498
### Type Design
@@ -536,7 +536,7 @@ struct FixedType {
536536
## FAQ
537537
538538
**Q: What happens when the pool is exhausted?**
539-
A: `allocate_object()` automatically allocates from heap. `free_object()` detects and deletes heap-allocated objects.
539+
A: `allocate()` automatically allocates from heap. `free()` detects and deletes heap-allocated objects.
540540
541541
**Q: Can I use std::string or std::vector in pooled objects?**
542542
A: Yes! The pool works with any default constructible type, including std::string, std::vector, and other standard containers.

include/slick/object_pool.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ namespace slick {
4343
* @endcode
4444
*
4545
* @section thread_safety Thread Safety
46-
* - Multiple threads can call allocate_object() concurrently (lock-free)
47-
* - Multiple threads can call free_object() concurrently (lock-free)
46+
* - Multiple threads can call allocate() concurrently (lock-free)
47+
* - Multiple threads can call free() concurrently (lock-free)
4848
* - reset() is NOT thread-safe
4949
*
5050
* @section example Example Usage
5151
* @code
5252
* slick::ObjectPool<MyStruct> pool(1024);
53-
* auto* obj = pool.allocate_object();
53+
* auto* obj = pool.allocate();
5454
* obj->field = value;
55-
* pool.free_object(obj);
55+
* pool.free(obj);
5656
* @endcode
5757
*
5858
* @tparam T Object type to pool
@@ -193,11 +193,11 @@ class ObjectPool {
193193
*
194194
* @par Example
195195
* @code
196-
* auto* obj = pool.allocate_object();
196+
* auto* obj = pool.allocate();
197197
* obj->value = 42;
198198
* @endcode
199199
*/
200-
T* allocate_object() {
200+
T* allocate() {
201201
auto [obj, size] = consume();
202202
if (!obj) {
203203
// Pool exhausted - allocate from heap
@@ -232,7 +232,7 @@ class ObjectPool {
232232
* @warning Do not free the same object twice
233233
* @warning Do not access object after calling free_object()
234234
*/
235-
void free_object(T* obj) {
235+
void free(T* obj) {
236236
auto o = reinterpret_cast<intptr_t>(obj);
237237
if (o >= lower_bound_ && o <= upper_bound_) {
238238
// Object belongs to pool - return it

tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ if(NOT GTest_FOUND)
66
include(FetchContent)
77
FetchContent_Declare(
88
googletest
9-
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
9+
GIT_REPOSITORY https://github.com/google/googletest.git
10+
GIT_TAG v1.17.0
1011
)
1112
# For Windows: Prevent overriding the parent project's compiler/linker settings
1213
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

0 commit comments

Comments
 (0)