Jonathan M Davis jmdavisProg at gmx.com
Mon Feb 13 18:56:16 PST 2012

On Monday, February 13, 2012 20:41:01 Zachary Lund wrote:
> On 02/11/2012 07:00 PM, Jonathan M Davis wrote:
> > On Sunday, February 12, 2012 01:40:50 Zachary Lund wrote:
> >> 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...
> > 
> > Read this:
> > 
> > http://www.dsource.org/projects/dcollections/wiki/ArrayArticle
> > 
> > Appending to vectors is very different from appending to dynamic arrays
> > because dynamic arrays do _not_ own their own memory (the GC does) and
> > not only could other slices refer the same memory (in which case, you
> > can't just free that memory when an array gets reallocated due to running
> > out of space to append to), but they could already refer to the memory
> > one past the end of the array, making it so that it can't expand into
> > that memory.
> > 
> > Slices change the entire equation. And the way slices are designed, they
> > require the GC.
> > 
> > - Jonathan M Davis
> Right but they use the same semantics and the information to do either
> seems to be present. I'm not sure why an abstraction between the two
> cannot be made.

I'm not sure what you're saying. All dynamic arrays are slices and _none_ of 
them own their own memory. As such, you need a way to manage their memory. 
Vectors, on the other hand, own their memory and do not allow slicing at all.

- Jonathan M Davis

More information about the Digitalmars-d mailing list