digitalmars.D.learn - Blog post about multidimensional arrays in D
- p.shkadzko (12/12) Mar 27 2020 I decided to write a small blog post about multidimensional
- WebFreak001 (14/30) Mar 27 2020 A static array doesn't really fall under this imo, because it
- p.shkadzko (4/9) Mar 27 2020 Ok, looks like I need to reread the slices topic. It always
- jmh530 (11/24) Mar 27 2020 Thanks for doing this.
- p.shkadzko (10/37) Mar 27 2020 I agree. I was planning to do several follow-ups after this first
- Jan =?UTF-8?B?SMO2bmln?= (10/19) Mar 30 2020 I am excited about your blog. Exactly what i have been waiting
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
Mar 27 2020
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.mdI 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) propertiesA 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 Dmeh, 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.
Mar 27 2020
On Friday, 27 March 2020 at 11:19:06 UTC, WebFreak001 wrote:On Friday, 27 March 2020 at 10:57:10 UTC, p.shkadzko wrote:Ok, looks like I need to reread the slices topic. It always confused me especially when it comes to function parameters but I just swallowed it and continued on. Thank you.[...]I don't really know mir myself, but for the start of the content: [...]
Mar 27 2020
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.mdThanks for doing this. A small typo on this line a.byDim1; I think there would be a lot of value in doing another blogpost to cover some more advanced topics. For instance, mir supports three different SliceKinds and the documentation explaining the difference has never been very clear. I don't really feel like I've ever had a clear understanding of the low-level differences between them. The pack/ipack/unpack functions are also pretty hard to understand from the documentation.
Mar 27 2020
On Friday, 27 March 2020 at 13:10:00 UTC, jmh530 wrote:On Friday, 27 March 2020 at 10:57:10 UTC, p.shkadzko wrote:I agree. I was planning to do several follow-ups after this first brief overview. For example, looks like just one "byDim" requires a separate post. The goal was just to show ppl who know nothing or a little about D and Mir that Mir exists and is usable. Because what I am lacking is not the API docs but introductory examples how to do mundane tasks like creating matrices and reshaping. Treat the first post as such and if you have suggestions on what is redundant or good to have I shall update it accordingly.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.mdThanks for doing this. A small typo on this line a.byDim1; I think there would be a lot of value in doing another blogpost to cover some more advanced topics. For instance, mir supports three different SliceKinds and the documentation explaining the difference has never been very clear. I don't really feel like I've ever had a clear understanding of the low-level differences between them. The pack/ipack/unpack functions are also pretty hard to understand from the documentation.
Mar 27 2020
On Friday, 27 March 2020 at 14:18:13 UTC, p.shkadzko wrote:I agree. I was planning to do several follow-ups after this first brief overview. For example, looks like just one "byDim" requires a separate post. The goal was just to show ppl who know nothing or a little about D and Mir that Mir exists and is usable. Because what I am lacking is not the API docs but introductory examples how to do mundane tasks like creating matrices and reshaping. Treat the first post as such and if you have suggestions on what is redundant or good to have I shall update it accordingly.I am excited about your blog. Exactly what i have been waiting for. If you plan to do more blog posts, please announce it in the "Announce" group and also on reddit (like Ron, e.g. https://forum.dlang.org/thread/gmqqkfzejicevkbaihqt forum.dlang.org). It really helps to "catch" it. Also, since you put so much work into it, you should put it somewhere (a link) on wiki.dlang.org (https://forum.dlang.org/post/orlwvfedaixnwiekqutx forum.dlang.org)
Mar 30 2020