You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/README.md
+52-8Lines changed: 52 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,30 +38,74 @@ There are three primary ways to write to the queue, each suited for a different
38
38
39
39
### High-Frequency Writes: `WriteTransaction`
40
40
41
-
This is the **highest-performance method** for producers that generate many individual items in a tight loop. It amortizes the cost of atomic operations over many fast, non-atomic pushes.
41
+
This is the **highest-performance API** for producers that generate many individual items in a tight loop. It amortizes the high cost of atomic synchronization over many fast, non-atomic pushes and emplaces.
42
+
43
+
The process involves three steps:
44
+
1. Start a transaction for a batch of items using `try_start_write()`.
45
+
2. If successful, use the transaction object's ultra-fast `try_emplace()` or `try_push()` methods to add items to the reserved space.
46
+
3. The transaction automatically commits the items that were successfully added when its `WriteTransaction` object is destroyed.
47
+
48
+
#### The `try_emplace` Method (Recommended for Complex Objects)
49
+
50
+
`try_emplace` is the most efficient way to add a complex object to the queue. It constructs the object **in-place** directly in the queue's memory, avoiding any temporary objects or expensive move operations.
0 commit comments