dcollections 1.0 and 2.0a beta released

Bill Baxter wbaxter at gmail.com
Fri May 21 09:56:41 PDT 2010


On Fri, May 21, 2010 at 9:43 AM, Steven Schveighoffer
<schveiguy at yahoo.com> wrote:
> superdan Wrote:
>
>> == Quote from Steven Schveighoffer (schveiguy at yahoo.com)'s article
>> > superdan Wrote:
>> > > == Quote from Steven Schveighoffer (schveiguy at yahoo.com)'s article
>> > > > Is there some other reason to use structs besides copy construction?
>> > > > -Steve
>> > >
>> > > memory management n shit. with a struct u can use refcounting n malloc n realloc n
>> > > shit. still stays a reference type. nothing gets fucked up.
>> > This is not necessary with purely memory-based constructs -- the GC is your
>> friend.  The custom allocator ability in dcollections should provide plenty of
>> freedom for memory allocation schemes.
>>
>> how do u set up yer custom allocator to free memory? u cant tell when its ok.
>> copying refs iz under da radar. dats my point.
>
> It frees an element's memory when the element is removed from the container.  The container itself is managed by the GC.
>
>>
>> > > den there's all that null ref shit. with a class u have
>> > >
>> > > void foo(container!shit poo)
>> > > {
>> > >     poo.addElement(Shit(diarrhea));
>> > > }
>> > >
>> > > dat works with struct but don't work with motherfucking classes. u need to write.
>> > >
>> > > void foo(container!shit poo)
>> > > {
>> > >     if (!poo) poo = new container!shit; // fuck dat shit
>> > >     poo.addElement(Shit(diarrhea));
>> > > }
>> > >
>> > > u feel me?
>> > It doesn't work.
>>
>> wut? it don't work? whaddaya mean it dun work? is you crazy? what dun work? maybe
>> therez sum misundercommunication.
>
> void foo(int[int] x)
> {
>   x[5] = 5;
> }
>
> void main()
> {
>   int[int] x;
>   foo(x);
>   assert(x[5] == 5); // fails
> }

And with arrays at least it's even more insidious, because sometimes
it will seem to work, and sometimes it won't.
void foo(int[] x) {
    x ~= 10;
}
Caller's .length will never get updated by that, but it won't crash so
it may take a while to find the bug.

Very easy bug to get caught by in D.  I'm pretty sure that one's
zapped me three or four times at least.  Probably because I started
thinking I wasn't going to modify the length of an array in a
particular function, then later I decide to (or in some function that
function calls).

--bb


More information about the Digitalmars-d-announce mailing list