From 2abbae77d707203f1ff1ddf03022c2146f35f185 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 29 May 2024 01:01:16 +0200 Subject: [PATCH] Library: draft memory rearrangements not clear yet how to handle the classical "realloc" situation --- src/lib/several-builder.hpp | 60 ++++++++++++++++++++++++++++++++++--- wiki/thinkPad.ichthyo.mm | 30 +++++++++++++++++++ 2 files changed, 86 insertions(+), 4 deletions(-) diff --git a/src/lib/several-builder.hpp b/src/lib/several-builder.hpp index 8634322f9..3b2401a8f 100644 --- a/src/lib/several-builder.hpp +++ b/src/lib/several-builder.hpp @@ -47,22 +47,27 @@ #include "lib/iter-explorer.hpp" #include "lib/util.hpp" +#include #include #include - namespace lib { using std::vector; using std::forward; using std::move; + using std::byte; - namespace {// Allocation managment policies + namespace {// Allocation management policies struct HeapOwn { - + void* + realloc (void* data, size_t oldSiz, size_t newSiz) + { + UNIMPLEMENTED ("adjust memory allocation"); ///////////////////////////OOO Problem Objekte verschieben + } }; } @@ -115,7 +120,54 @@ namespace lib { void adjustStorage (size_t cnt, size_t spread) { - UNIMPLEMENTED ("allocation"); + if (cnt*spread > storageSiz_) + {// need more storage.. + Col::data_ = static_cast (POL::realloc (Col::data_, storageSiz_, cnt*spread)); + storageSiz_ = cnt*spread; + } + ENSURE (Col::data_); + if (spread != Col::data_->spread) + adjustSpread (spread); + + if (cnt*spread < storageSiz_) + {// attempt to shrink storage + Col::data_ = static_cast (POL::realloc (Col::data_, storageSiz_, cnt*spread)); + storageSiz_ = cnt*spread; + } + } + + /** move existing data to accommodate spread */ + void + adjustSpread (size_t newSpread) + { + REQUIRE (Col::size_); + REQUIRE (Col::data_); + REQUIRE (newSpread * Col::size_ <= storageSiz_); + size_t oldSpread = Col::data_->spread; + if (newSpread > oldSpread) + // need to spread out + for (size_t i=Col::size_-1; 0spread = newSpread; + } + + void + shiftStorage (size_t idx, size_t oldSpread, size_t newSpread) + { + REQUIRE (idx); + REQUIRE (oldSpread); + REQUIRE (newSpread); + REQUIRE (Col::data_); + byte* oldPos = Col::data_->storage; + byte* newPos = oldPos; + oldPos += idx * oldSpread; + newPos += idx * newSpread; + std::memmove (newPos, oldPos, util::min (oldSpread,newSpread)); } template diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 22589bb90..59ea1f6b8 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -81870,6 +81870,25 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + + + + + + + + + + + @@ -81880,10 +81899,21 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + + +