Bug 3112 – Specification on what operations call the GC is missing

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
Other
OS
All
Creation time
2009-06-29T18:41:00Z
Last change time
2014-04-18T09:12:07Z
Keywords
spec
Assigned to
nobody
Creator
leandro.lucarella
Blocks
677

Comments

Comment #0 by leandro.lucarella — 2009-06-29T18:41:43Z
There are several languages constructs that rely on the GC and use it, like array concatenation and appending. This operations are not properly documented.
Comment #1 by bugzilla — 2010-11-10T00:25:48Z
Comment #2 by janda.petr — 2010-12-21T23:40:16Z
Why are things such as array concat and appending relying on GC? It looks to me as that a lot of them could be accomplished without it.
Comment #3 by issues.dlang — 2010-12-22T00:03:29Z
They use the GC for two reasons of which I am aware: 1. They potentially have to reallocate. That means allocating memory which normally means using the GC. And since there's no way to tell something like ~= to use malloc() (and potentially free()) instead of the GC, it _has_ to use the GC. 2. As I understand it, the GC does some sort of voodoo to determine whether an array actually has the capacity to increase its size in place. That's likely going to have to figure out whether _other_ arrays refer to the memory immediately after the end of the array, which would somehow involve looking at the other arrays, which would require the GC, since one malloc-ed item knows nothing about another malloc-ed item. The fact that you have slicing likely complicates things a fair bit. It would probably be possible to do array concatenation and appending without the GC if arrays were not designed to use the GC (after all, vectors in C++ are able to reallocate without the GC), but since they _do_ use the GC, they have to use the GC for operations which would result in reallocating memory. Actually, I believe that Steven pointed out on the list recently that you _can_ use appending with non-GCed dynamic arrays but that you have to maintain references to the original before you append so that you can free that memory if you need to. So, it _is_ possible, but it doesn't work very well.