February 20, 2012 Re: std.collection lets rename it into std,ridiculous. | ||||
---|---|---|---|---|
| ||||
Posted in reply to a | On Mon, Feb 20, 2012 at 07:42:07PM +0100, a wrote: > >But if you only access it via push() and pop(), then there are no > >other references to the stack, so why should the GC reallocate it > >on append? > > Because the GC doesn't know there aren't any other references to it unless you tell it with assumeSafeAppend. Ahh, I see. Thanks! T -- Being able to learn is a great learning; being able to unlearn is a greater learning. |
February 20, 2012 Re: std.collection lets rename it into std,ridiculous. | ||||
---|---|---|---|---|
| ||||
On Monday, February 20, 2012 11:40:40 H. S. Teoh wrote: > On Mon, Feb 20, 2012 at 07:42:07PM +0100, a wrote: > > >But if you only access it via push() and pop(), then there are no > > >other references to the stack, so why should the GC reallocate it > > >on append? > > > > Because the GC doesn't know there aren't any other references to it unless you tell it with assumeSafeAppend. > > Ahh, I see. Thanks! Nick ran into this problem and ended up writing an article on it: https://www.semitwist.com/articles/article/view/don-t-use-arrays-as-stacks And, of course, if you haven't read Steven's article on arrays, you should read that: http://www.dsource.org/projects/dcollections/wiki/ArrayArticle In fact, we really should get Steven's article up on dlang.org. It's one of those articles that _every_ D programmer should read. - Jonathan M Davis |
February 20, 2012 Re: std.collection lets rename it into std,ridiculous. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On 2/20/12 1:45 PM, Jonathan M Davis wrote:
> In fact, we really should get Steven's article up on dlang.org. It's one of
> those articles that _every_ D programmer should read.
Pull request before we forget about that please.
Thanks,
Andrei
|
February 20, 2012 Re: std.collection lets rename it into std,ridiculous. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Monday, February 20, 2012 14:55:36 Andrei Alexandrescu wrote:
> On 2/20/12 1:45 PM, Jonathan M Davis wrote:
> > In fact, we really should get Steven's article up on dlang.org. It's one
> > of
> > those articles that _every_ D programmer should read.
>
> Pull request before we forget about that please.
Steven's the one with the actual article though. He's going to have to do it. The best that any of the rest of us can do is copy the HTML over. If it's anything like the other articles on dlang.org, it was generated using ddoc, and that's what we'd want to commit to the repository.
- Jonathan M Davis
|
February 20, 2012 Re: std.collection lets rename it into std,ridiculous. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu Attachments:
| On Mon, Feb 20, 2012 at 1:55 PM, Andrei Alexandrescu < SeeWebsiteForEmail@erdani.org> wrote:
> On 2/20/12 1:45 PM, Jonathan M Davis wrote:
>
>> In fact, we really should get Steven's article up on dlang.org. It's one
>> of
>> those articles that _every_ D programmer should read.
>>
>
> Pull request before we forget about that please.
>
> Thanks,
>
> Andrei
>
Where does an article like that go? It seems like the D website is missing
a "Concepts" section with high level descriptions of certain core features.
The language reference is too low level for most beginners. The Articles
section doesn't feel right to me (I wouldn't think to check there to figure
out how slices or ranges work). Perhaps add a Concepts section, move the
appropriate articles over from Articles, and keep Articles around for
interesting topics that wouldn't belong in Concepts (like Don's floating
point article, most of the iPad contest entries, and this "don't use arrays
as stacks article").
Another great article for a Concepts section would be the recent book excerpt on ranges that was released a month or two ago (if the author would allow it). Ranges are painfully undocumented (I only had an understanding of them because I had watched Andrei's BoostCon talk).
Regards,
Brad Anderson
|
February 24, 2012 Re: std.collection lets rename it into std,ridiculous. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Mon, 20 Feb 2012 16:03:19 -0500, Jonathan M Davis <jmdavisProg@gmx.com> wrote:
> On Monday, February 20, 2012 14:55:36 Andrei Alexandrescu wrote:
>> On 2/20/12 1:45 PM, Jonathan M Davis wrote:
>> > In fact, we really should get Steven's article up on dlang.org. It's
>> one
>> > of
>> > those articles that _every_ D programmer should read.
>>
>> Pull request before we forget about that please.
>
> Steven's the one with the actual article though. He's going to have to do it.
> The best that any of the rest of us can do is copy the HTML over. If it's
> anything like the other articles on dlang.org, it was generated using ddoc,
> and that's what we'd want to commit to the repository.
I'm sorry, I promised to do this a long time ago. When I have time to pay attention to D again (I've been super-busy at work and home for the last 2 weeks), this is the first thing I will do.
It's generated using TRAC Wiki, it should be pretty trivial to convert to ddoc.
-Steve
|
February 24, 2012 Re: std.collection lets rename it into std,ridiculous. | ||||
---|---|---|---|---|
| ||||
Posted in reply to a | On Mon, 20 Feb 2012 11:22:32 -0500, a <a@a.com> wrote:
>> auto a = [1,2,3,4,5];
>> auto b = a[0..3];
>> assumeSafeAppend(b);
>> b ~= 0;
>> writeln(a);
>>
>> prints [1, 2, 3, 0, 5], so b is not reallocated in this case.
>
> Just to clarify: this is not guaranteed to print [1, 2, 3, 0, 5], it only does
> if there is still enough memory in a block allocated to b and it doesn't have
> to be reallocated.
In fact, it is guaranteed. a is guaranteed to be allocated on the heap, because that's what an array literal does (currently, but it probably shouldn't be). It's guaranteed to be inserted into a block large enough to hold 5 numbers, so you definitely can put 4 numbers (1, 2, 3, 0) into it. This will never reallocate.
However, It's not guaranteed that the last number will be 5 after assumeSafeAppend is called. Once you call assumeSafeAppend, all data after that last element is invalid (i.e. not used). To refer to that data is implementation-defined. E.g. a different version of assumeSafeAppend may set all invalid bytes to 0, or some other sentinel value.
-Steve
|
February 24, 2012 Re: std.collection lets rename it into std,ridiculous. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Friday, February 24, 2012 11:34:11 Steven Schveighoffer wrote:
> I'm sorry, I promised to do this a long time ago. When I have time to pay attention to D again (I've been super-busy at work and home for the last 2 weeks), this is the first thing I will do.
>
> It's generated using TRAC Wiki, it should be pretty trivial to convert to ddoc.
Just so long as it's not forgotten. We all get busy. I haven't had as much time for D lately either, and there are some Phobos things that I definitely need to get back to and get done.
- Jonathan M Davis
|
March 06, 2012 Re: std.collection lets rename it into std,ridiculous. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Fri, 24 Feb 2012 11:34:11 -0500, Steven Schveighoffer <schveiguy@yahoo.com> wrote: > On Mon, 20 Feb 2012 16:03:19 -0500, Jonathan M Davis <jmdavisProg@gmx.com> wrote: > >> On Monday, February 20, 2012 14:55:36 Andrei Alexandrescu wrote: >>> On 2/20/12 1:45 PM, Jonathan M Davis wrote: >>> > In fact, we really should get Steven's article up on dlang.org. It's >>> one >>> > of >>> > those articles that _every_ D programmer should read. >>> >>> Pull request before we forget about that please. >> >> Steven's the one with the actual article though. He's going to have to do it. >> The best that any of the rest of us can do is copy the HTML over. If it's >> anything like the other articles on dlang.org, it was generated using ddoc, >> and that's what we'd want to commit to the repository. > > I'm sorry, I promised to do this a long time ago. When I have time to pay attention to D again (I've been super-busy at work and home for the last 2 weeks), this is the first thing I will do. As promised: https://github.com/D-Programming-Language/d-programming-language.org/pull/97 And now I'm finally caught up in the newsgroup! -Steve |
March 06, 2012 Re: std.collection lets rename it into std,ridiculous. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On 6 March 2012 14:15, Steven Schveighoffer <schveiguy@yahoo.com> wrote:
> On Fri, 24 Feb 2012 11:34:11 -0500, Steven Schveighoffer <schveiguy@yahoo.com> wrote:
>
>> On Mon, 20 Feb 2012 16:03:19 -0500, Jonathan M Davis <jmdavisProg@gmx.com> wrote:
>>
>>> On Monday, February 20, 2012 14:55:36 Andrei Alexandrescu wrote:
>>>>
>>>> On 2/20/12 1:45 PM, Jonathan M Davis wrote:
>>>> > In fact, we really should get Steven's article up on dlang.org. It's
>>>> > one
>>>> > of
>>>> > those articles that _every_ D programmer should read.
>>>>
>>>> Pull request before we forget about that please.
>>>
>>>
>>> Steven's the one with the actual article though. He's going to have to do
>>> it.
>>> The best that any of the rest of us can do is copy the HTML over. If it's
>>> anything like the other articles on dlang.org, it was generated using
>>> ddoc,
>>> and that's what we'd want to commit to the repository.
>>
>>
>> I'm sorry, I promised to do this a long time ago. When I have time to pay attention to D again (I've been super-busy at work and home for the last 2 weeks), this is the first thing I will do.
>
>
> As promised: https://github.com/D-Programming-Language/d-programming-language.org/pull/97
>
> And now I'm finally caught up in the newsgroup!
>
> -Steve
Awesome work Steve, your original article was brilliant, clearly explained how D arrays and slices work without out segueing into other topics, which tends to happen with these kinds of articles.
--
James Miller
|
Copyright © 1999-2021 by the D Language Foundation