a at a.a
Sat Feb 11 15:01:05 PST 2012
"Jonathan M Davis" <jmdavisProg at gmx.com> wrote in message
news:mailman.242.1328986002.20196.digitalmars-d at puremagic.com...
> On Saturday, February 11, 2012 19:00:51 q66 wrote:
>> What's so difficult on that? Slices do not require the GC, you
>> allocate once, slice many times, deallocate once.
> With dynamic arrays, the GC owns the memory, and _all_ dynamic arrays are
But not all slices are slices of dynamic arrays.
> _None_ of them own their own memory. The GC keeps track of whether you
> have any slices for a particular memory block and deals with freeing up
> the block if you don't. However, if you allocate a dynamic array without
> GC, then all of a sudden, it effectively owns its own memory, so the
> of dealing with arrays and memories changes drastically. What happens when
> slice it? Which one owns the memory? What happens when you try and do
> like popFront on an array? All of a sudden, you have memory which is no
> referenced. It's been leaked.
> If you have a very careful scheme for handling memory, you _can_ slice
> without a GC, but you have to worry about all the bookkeeping of keeping
> of the originally allocated memory and how many slices reference it so
> you can free it when appropriate.
Yea, manual memory management is hard and you have to be careful. That's
true slices or not.
> Also, you can't concatenate to arrays at all, because that requires the
That's true (at least without providing some way to provide an alternate
concatenation allocator). But nobody said that all D features would be
> So, you're dealing with a mine field if you try and use D's array
> without a GC. Yes, you _can_ use some of them if you're _very_ careful,
> I'd seriously advise just sticking to using arrays like you would in C
> for the fact that arrays know their length.
Arrays knowing their own length *is* a notable improvement over C.
More information about the Digitalmars-d