Re: Slice allocation after appending

2020-12-23 Thread Ali Çehreli via Digitalmars-d-learn
On 12/23/20 8:14 AM, frame wrote: > That implementation > can become very handy for some situations but for this simple case > > foreach (arr; [a, b]) { .. } > > would also work. Absolutely. > The difference is that the foreach loop is happen at > runtime and will not compiled as multiple lines

Re: Slice allocation after appending

2020-12-23 Thread frame via Digitalmars-d-learn
On Wednesday, 23 December 2020 at 11:19:38 UTC, Rekel wrote: I'm not sure what your aliasSeq does, sadly I don't find the documentation's explanation satisfactory. Try to write static foreach (arr; [a, b]) { .. } - it will not work because that loop is generated at compile time (static). It

Re: Slice allocation after appending

2020-12-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/22/20 5:12 PM, Rekel wrote: According to the D slice article (https://dlang.org/articles/d-array-article.html), slices do not care where they start, only where they end, when checking whether expanding in place is permitable, or at least that is what I understood regarding it. Now I'm u

Re: Slice allocation after appending

2020-12-23 Thread Rekel via Digitalmars-d-learn
On Wednesday, 23 December 2020 at 04:03:37 UTC, Ali Çehreli wrote: It is valid. One can always copy the small array before appending to it and the large array would be preserved. Try the -profile command line switch when compiling your program and it will show where memory allocations occur.

Re: Slice allocation after appending

2020-12-22 Thread Ali Çehreli via Digitalmars-d-learn
On 12/22/20 2:12 PM, Rekel wrote: > Now I'm unsure how to check this, I tried to a bit using the online > editor and a bit of pointer usage which seemed to confirm my suspicion, > but does this mean that taking a (small) slice at the end of a > (possibly) very large dynamic array can lead to prob

Re: Slice allocation after appending

2020-12-22 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 22 December 2020 at 22:12:29 UTC, Rekel wrote: According to the D slice article (https://dlang.org/articles/d-array-article.html), slices do not care where they start, only where they end, when checking whether expanding in place is permitable, or at least that is what I understood

Slice allocation after appending

2020-12-22 Thread Rekel via Digitalmars-d-learn
According to the D slice article (https://dlang.org/articles/d-array-article.html), slices do not care where they start, only where they end, when checking whether expanding in place is permitable, or at least that is what I understood regarding it. Now I'm unsure how to check this, I tried t