From 339f1ce9d67f8f91faf9bcb92ed36b273fb3f6b3 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 25 Feb 2026 09:30:59 -0500 Subject: [PATCH] README: note managed pointer size differences between rcp and shared_ptr --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d0f786c..a41c9d5 100644 --- a/README.md +++ b/README.md @@ -319,6 +319,7 @@ for (auto & l : g_listeners) l->events_received++; | | `rcp` | `std::shared_ptr` | |---|---|---| +| Pointer size | One pointer | Two pointers (object + control block) | | Reference count location | Inside the object | Separate control block (extra allocation) | | Class requirement | `rcp_managed_root` / `rcp_managed` macro | None (any type) | | Weak pointers | No | Yes (`std::weak_ptr`) | @@ -326,7 +327,14 @@ for (auto & l : g_listeners) l->events_received++; | Pointer to `this` | implicit conversion from `this` or explicit `get_rcp()` | `std::enable_shared_from_this` | | Checked downcast | `rcp_dynamic_cast` | `std::dynamic_pointer_cast` | -The intrusive design means each managed object requires only one heap +Because `rcp` stores only a single raw pointer, `sizeof(rcp)` equals +`sizeof(T *)` — typically 8 bytes on a 64-bit platform. +`std::shared_ptr` stores both a pointer to the object and a pointer to the +control block, so `sizeof(std::shared_ptr)` is typically 16 bytes. +This makes `rcp` more efficient to pass by value, copy, and store in +containers. + +The intrusive design also means each managed object requires only one heap allocation instead of two which can improve performance for many applications. The trade-off is that the class must be written with `rcp` in mind.