On Sunday, 12 February 2012 at 00:29:35 UTC, Jonathan M Davis wrote:
On Saturday, February 11, 2012 18:01:05 Nick Sabalausky wrote:
But not all slices are slices of dynamic arrays.

But all slices are still dynamic arrays, even if they refer to a static array. They just have a capacity of 0, so any appending will result in them being reallocated. And slicing static arrays is one of those things that you generally have to be careful about precisely because they aren't managed by the GC and can go out of scope before their slices do.

Yea, manual memory management is hard and you have to be careful. That's
true slices or not.

Yes, but in this case, you're dealing with a language feature which is _designed_ to be managed by the GC. It's not designed for manual memory management at all. It's a completely different situation when you're dealing with user-defined types.

Arrays knowing their own length *is* a notable improvement over C.

Indeed, but that's pretty much the only improvement that D makes to arrays which is safe to use without a GC without being _very_, _very_ careful.

- Jonathan M Davis

Btw, I'm not very fluent in the inner workings of a garbage collector implementation but how does one go about concatenating to an array in a garbage collector as compared to manual memory management? I believe array concatenation can be done in std::vector with the insert() function just fine. Isn't it as simple as determining both array sizes and allocating enough memory for both arrays? I could be oversimplifying things...

Reply via email to