From f6e4358259e8738af736145bb03cd1ae491ce74c Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Tue, 28 May 2024 17:20:34 +0200 Subject: [PATCH] Library: data layout for the new `Several` container - favour dynamic polymorphism - use additional memory for management data alongside the element allocation - encode a flag and a deleter pointer to enable ownership of the allocation - inherit base container privately into builder, so the build ends with a slice --- src/lib/several-builder.hpp | 12 ++- src/lib/several.hpp | 40 ++++++++- wiki/thinkPad.ichthyo.mm | 158 ++++++++++++++++++++++++++++++++++++ 3 files changed, 206 insertions(+), 4 deletions(-) diff --git a/src/lib/several-builder.hpp b/src/lib/several-builder.hpp index 316782933..96f6f95dd 100644 --- a/src/lib/several-builder.hpp +++ b/src/lib/several-builder.hpp @@ -53,12 +53,22 @@ using std::vector; namespace lib { + namespace {// Allocation managment policies + + struct HeapOwn + { + + }; + } + /** * Wrap a vector holding objects of a subtype and * provide array-like access using the interface type. */ - template + template class SeveralBuilder + : Several + , POL { public: diff --git a/src/lib/several.hpp b/src/lib/several.hpp index 9786d9e31..743c55a62 100644 --- a/src/lib/several.hpp +++ b/src/lib/several.hpp @@ -36,22 +36,56 @@ #include "lib/nocopy.hpp" +#include "lib/iter-adapter.hpp" + +#include namespace lib { - /** - * Abstraction: Array of const references. + namespace {// Storage implementation details + + struct Bucket + { + union Manager + { + typedef void (*Deleter) (void*, size_t); + + bool unmanaged :1; + Deleter deleter; + }; + + Manager manager; + size_t spread; + }; + + template + struct ArrayBucket + : Bucket + { + alignas(I) + std::byte storage[bytes]; + }; + + }//(End)implementation details + + + + /************************************************//** + * Abstraction: Fixed array of elements. * Typically the return type is an interface, * and the Implementation wraps some datastructure * holding subclasses. - * @todo ouch -- a collection that isn't iterable... ///////////////////////TICKET #1040 //////////OOO cookie jar * @warning in rework 5/2025 */ template class Several : util::MoveOnly { + protected: + size_t size_{0}; + Bucket* data_{nullptr}; + public: size_t diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 19cc53a97..5c1656df8 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -81665,11 +81665,36 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + + + + + + +

+ Konsequenz: man kann einen einzigen Typ Several<X> anschreiben +

+ + +
+
+ + + +
@@ -81694,6 +81719,139 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ ...und zwar vor allem durch den AllocationCluster mit einer festen Extent-Size. Vorhersehbar werden die Extents meist zu groß sein... +

+ + +
+
+ + + + + + +

+ ...und was noch besser ist: die Storage liegt kompakt +

+ + +
+
+ + + + + + +

+ ...weil wir durch den Connectivity-Descriptor bereits eine gefährlich komplexes Stück Metaprogramming haben, mit dem Risiko kombinatorischer Explosion +

+ + +
+
+
+ + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ diese Funktion würde eine Exception werfen, wen das ArrayBucket eben doch ownership-managed ist. Ansonsten erzeugt sie eine neue Instanz mit Verweis auf das gemeinsam nutzbare Bucket +

+ + +
+
+
+
+ + + + + + + + + + + + + + + + + + +