On Friday, 27 March 2020 at 10:57:10 UTC, p.shkadzko wrote:
I decided to write a small blog post about multidimensional
arrays in D on what I learnt so far. It should serve as a brief
introduction to Mir slices and how to do basic manipulations
with them. It started with a small file with snippets for
personal use but then kind of escalated into an idea of a blog
post.
However, given the limited about of time I spent in Mir docs
and their conciseness, it would be great if anyone had a second
look and tell me what is wrong or missing because I have a
feeling a lot of things might. It would be a great opportunity
for me to learn and also improve it or rewrite some parts.
All is here:
https://github.com/tastyminerals/tasty-blog/blob/master/_posts/2020-03-22-multidimensional_arrays_in_d.md
I don't really know mir myself, but for the start of the content:
Both array types represent a structure with a length and ptr (a
pointer to the first element) properties
A static array doesn't really fall under this imo, because it
doesn't have any length field at runtime and is literally just
the elements repeated N times.
Dynamic arrays are also called slices in D
meh, all dynamic arrays are also slices, but not all slices are
dynamic arrays. You can take a slice from a static array or from
a pointer and once you try to append to it or resize it, it will
duplicate the data using the GC and create a new dynamic array.
This is true every time you take a slice of any array or memory
and then try to resize it. If the slice was originally from a
dynamic array (checked using runtime magic) and you use
assumeSafeAppend, it will actually try to resize the existing
array in-place.