Skip to content

Commit 18daa2e

Browse files
committed
irc: Explain the benefits in the doc
1 parent a45817c commit 18daa2e

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This crate provides two categories of modules:
2323
- std `Box` (owned),
2424
- std `Arc`, `Rc` (multiple ownership)
2525
- [Irc](https://docs.rs/embed-collections/latest/embed_collections/irc/): Highly customized Intrusive Reference Counter. See the detail in
26-
module doc.
26+
module doc.
2727
- [WaitGroupZeroGuard](https://docs.rs/crossfire/latest/crossfire/waitgroup/struct.WaitGroupZeroGuard.html): see the doc in `crossfire` crate
2828
- raw pointers (`NonNull<T>`, `*const T`, `*mut T`)
2929
- Structs:
@@ -32,7 +32,6 @@ This crate provides two categories of modules:
3232
- [slist_owned](https://docs.rs/embed-collections/latest/embed_collections/slist_owned/): An intrusive slist but with safe and more compact interface
3333
- [avl](https://docs.rs/embed-collections/latest/embed_collections/avl/): Intrusive AVL Tree (Balanced Binary Search Tree), port to rust from ZFS
3434

35-
3635
**Disclaimer**
3736

3837
Intrusive code is not recommended unless you are full aware of what you are doing.
@@ -151,7 +150,7 @@ There're three usage scenarios:
151150

152151
2. Push `Box` to the list, the list own the items until they are popped, it's better than std
153152
LinkedList because no additional allocation is needed. It will not move the item
154-
in-and-out of hidden `Box` on every push / pop.
153+
in-and-out of hidden `Box` on every push / pop.
155154

156155
3. Push raw pointer (better use NonNull instead of *const T for smaller footprint) to the list,
157156
for temporary usage. You must ensure the list item not dropped be other refcount

src/irc.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,27 @@
66
//! The underlayer of `Irc` is Box, unlike `Arc` which wrap a hidden ArcInner on your inner types,
77
//! Irc use the same memory location of your inner types.
88
//!
9-
//! [IrcItem::on_drop] in the trait allow you to have the ownship of underlying inner memory after the reference count of Irc is dropped.
9+
//! # Benefits
1010
//!
11-
//! # Example
11+
//! - No need to manual implementing the inc / dec on counter.
12+
//!
13+
//! - No enforced weak counter if you don't need it (every atomic op has cost).
14+
//!
15+
//! - [IrcItem::on_drop] in the trait allow you to have the ownship of underlying inner memory after
16+
//! the reference count of Irc is dropped. And you only need to define the drop behavior once,
17+
//! instead of write the same logic `Arc::into_inner` in every possible places
18+
//! (If forgetting so make your code block and hard to debug).
19+
//!
20+
//! - Using `Irc` to wrap a `Box`, no additional memory allocation and memory fragmentation, no
21+
//! additional dereference cost (than using `Arc<Box<T>>`)
22+
//!
23+
//! - You can allocate a box from the time of its birth and wrap it will `Irc` for temporary usage,
24+
//! don't need to move bytes from / to stack. (especially when the inner object is large)
25+
//!
26+
//! - Advanced usage, multiple layer customized counter, on the same heap object, while preserving
27+
//! the safe boundary
28+
//!
29+
//! # Example (Irc wrapping a Box)
1230
//!
1331
//! ```rust
1432
//! use embed_collections::irc::{Irc, IrcItem};

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
//! - std `Box` (owned),
2222
//! - std `Arc`, `Rc` (multiple ownership)
2323
//! - [Irc](crate::irc): Highly customized Intrusive Reference Counter. See the detail in
24-
//! module doc.
24+
//! module doc.
2525
//! - [WaitGroupZeroGuard](https://docs.rs/crossfire/latest/crossfire/waitgroup/struct.WaitGroupZeroGuard.html): see the doc in `crossfire` crate
2626
//! - raw pointers (`NonNull<T>`, `*const T`, `*mut T`)
2727
//! - Structs:
@@ -148,7 +148,7 @@
148148
//!
149149
//! 2. Push `Box` to the list, the list own the items until they are popped, it's better than std
150150
//! LinkedList because no additional allocation is needed. It will not move the item
151-
//! in-and-out of hidden `Box` on every push / pop.
151+
//! in-and-out of hidden `Box` on every push / pop.
152152
//!
153153
//! 3. Push raw pointer (better use NonNull instead of *const T for smaller footprint) to the list,
154154
//! for temporary usage. You must ensure the list item not dropped be other refcount

0 commit comments

Comments
 (0)