News for hackers. Stuff that matters.
Re:C++ Core Coroutines Proposal [pdf] by BurnGpuBurn on Friday September 21, 2018 @04:47AM (#18038158)
Memory allocation by STL has been broken for as long as I remember, which is at least twelve years or so. It's been a while but if I remember correctly it doubled its allocation every time it ran out or space.
Re:C++ Core Coroutines Proposal [pdf] by jcelerier on Friday September 21, 2018 @06:06AM (#18038518)
> It's been a while but if I remember correctly it doubled its allocation every time it ran out or space.

why would you call this "broken" ? That's one of the most optimal solutions for reallocations if you append values continuously, since it will reallocate only logarithmically.

Re:C++ Core Coroutines Proposal [pdf] by EpicEng on Friday September 21, 2018 @11:31AM (#18040417)
Which libs _don't_ use that allocation strategy? The fact that you think it's broken only means you don't really know what you're talking about.
Re:C++ Core Coroutines Proposal [pdf] by gmadsen on Friday September 21, 2018 @07:28AM (#18038883)
what? ha, that is the text book approach to reallocating an array for additional values to get log complexity
Re:C++ Core Coroutines Proposal [pdf] by vardump on Friday September 21, 2018 @08:01AM (#18039035)
I'm not so sure I'd want a 2GB vector to grow to 4GB, etc.
Re:C++ Core Coroutines Proposal [pdf] by ChrisSD on Friday September 21, 2018 @08:29AM (#18039182)
In such extreme cases you can (and should) use your own allocation strategy.
Re:C++ Core Coroutines Proposal [pdf] by vardump on Friday September 21, 2018 @08:41AM (#18039234)
Yeah, but I'm not entirely clear how I'd for example get std::vector to use a mmap'ed range, that I could zero-copy grow.

Also in that case I might want to grow it by a fixed amount, once it grows past a certain threshold.

It's a shame one needs to write another vector implementation just for that.

Re:C++ Core Coroutines Proposal [pdf] by ChrisSD on Friday September 21, 2018 @08:46AM (#18039266)
Why wouldn't writing an allocator class be enough for mmap?
Re:C++ Core Coroutines Proposal [pdf] by BeeOnRope on Friday September 21, 2018 @12:21PM (#18040769)
Probably not, because the allocators don't expose the "extend" or "realloc" concept, so all you'll see from within your allocator is a request for an entire new region that vector wants in order to copy the new stuff into.

To implement a growing allocation , you'll have to create a custom vector, pretty much.

Re:C++ Core Coroutines Proposal [pdf] by Timmah on Friday September 21, 2018 @12:19PM (#18040755)
How would you ensure nothing was used in the region after the original allocation?
Re:C++ Core Coroutines Proposal [pdf] by dbaupp on Friday September 21, 2018 @08:21AM (#18039142)
O(n^2) time for n push_back calls would be worse, so some sort of multiplication/exponential growth is required for the "fits all" default vector and its default growth strategy.
Re:C++ Core Coroutines Proposal [pdf] by BeeOnRope on Friday September 21, 2018 @12:23PM (#18040783)
Old versions of MSVC used a 3/2 growth factor which led to less extreme jumps for large vectors, although also a lot more copies when filling a small vector. I'm not sure if that's still true.
Re:C++ Core Coroutines Proposal [pdf] by jhasse on Friday September 21, 2018 @08:11AM (#18039082)
Why not?
Re:C++ Core Coroutines Proposal [pdf] by mortehu on Friday September 21, 2018 @07:41PM (#18043481)
I think you mean amortized constant complexity, or O(1).
Re:C++ Core Coroutines Proposal [pdf] by NullPrefix on Friday September 21, 2018 @05:21AM (#18038331)
this is implementation specific. Care to tell which compiler are you talking about?