-
-
Notifications
You must be signed in to change notification settings - Fork 416
Add better array extending function #620
Add better array extending function #620
Conversation
I'll also be glad to see alternative solutions and causes current |
It will take some time for me to wrap my head around this so it won't happen too soon. |
There should be an associated public |
Yes, but probably in another pull as I don't want discussion about public API change to delay merging of this. |
ping |
Merge conflict. Please rebase. |
This looks useful - any chance we can restart it? |
I'm trying to understand the difference between requested capacity and desired capacity. The documentation is not really helpful. |
E.g. when we are building an array |
I think part of my confusion is I assumed So let me throw this strawman definition out there: reqSize -> Size you absolutely need the array to grow to. Algorithm:
An interesting optimization would be to allocate a block between reqSize and desSize if extension isn't possible. But maybe that's not such a good thing, if you are running low on memory, better not consume it all. If this is the case, can you put something similar into the docs? Also document better the "ability to discard current array" -- just say that it calls postblit on original array if true :) I like the idea, BTW. Wish I would have done arraySetCapacity this way to begin with :) |
ping - rebase and mind failures? |
Last time I thought about this (~1 year ago) I couldn't come up with a single use-case where I require a certain amount of memory but actually want more in order to do something more efficient. |
Interesting. This pull is just a practical requirement for array builder. |
You mean appender? How is that? Appender already knows the how much memory was actually allocated and can reuse that until it needs to realloc. |
When we are out of capacity, we need to grow. And to grow we need a function which accepts how much memory we do require and how much memory we just want to be allocated to decrease future allocations count. As we currently lack such function in druntime this pull was created. |
There are two schemes that already work equally well. |
Looks like it's not appreciated and was there for 2 years.Closing |
An attempt to create a function to use in
std.array.appender
and anticipated (let's correct: needed in most cases IMO) "real appender" from Issue 11138.I'm not good in D internals but what happens now in
std.array.appender
looks like a total mess as it attempts to create D array but doesn't respect any hidden info at all.Accidentally it is requested in Issue 9313 - Provide dynamic array-dedicated "extend" function.