Bug 4091 – Small docs page about dynamic array implementation

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-04-14T15:05:00Z
Last change time
2015-06-09T05:13:47Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-04-14T15:05:09Z
I suggest to add a very short page to D docs on the digitalmars site (for example in the "Articles" section) that explains how dynamic arrays are implemented and exactly how this data structure works regarding item append (and maybe why this is the chosen design of arrays instead of other possible designs, and how it interacts with the current GC). The purpose of this short text is to help D programmers understand what dynamic arrays are and why they work this way in their programs. Often it's not necessary to know how an object manages its inner data, but: - Dynamic arrays are a basic data structure in D, they are among the most common data structure in D programs, so they are quite important. - From what I have seen so far it's quite not intuitive how the current dynamic arrays work and how they are implemented in the runtime. - Dynamic arrays, as objects in OOP, are an abstraction. But from what I have seen so far the current implementation of D dynamic arrays is an abstraction that leaks a lot (http://en.wikipedia.org/wiki/Leaky_abstraction ), to program efficiently with arrays you must predict how they behave, but I've seen that this is hard to do if you don't know how they are implemented. This HTML page can also contain one or two images with boxes & pointers, to help the explanation. In case of need I can help in creating such images. D specs don't need to fully specify how dynamic array append is implemented, this detail can be left to front-end implementations. So this HTML page is not part of D specs, it's documentation to help D programmers that use the dmd front-end.
Comment #1 by dfj1esp02 — 2010-04-16T13:19:15Z
To understand a system programming language "abstraction", OOP and Grady Booch are not the right way to go :3 Implementation is not abstract, it's concrete.
Comment #2 by bearophile_hugs — 2010-04-19T01:14:03Z
I don't understand what your point it. D dynamic arrays are not simple things, they contain pointers, length, the GC keeps the length of the allocated memory, they have a capacity and a cache. They are managed by the GC, so they are not just are chunk of raw memory. So an append to a D dynamic array is an abstraction, it's an high-level operation. What I meant to say is that to program in D it's quite important to understand this specific abstraction. So in my opinion a docs page about them can be useful.
Comment #3 by andrej.mitrovich — 2012-10-21T20:35:23Z
We now have this: http://dlang.org/d-array-article.html If insufficient feel free to reopen and add suggestions.