shared array?

Prudence via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 11 14:48:13 PDT 2015


On Friday, 11 September 2015 at 20:30:37 UTC, Adam D. Ruppe wrote:
> On Friday, 11 September 2015 at 20:06:53 UTC, Prudence wrote:
>> Can you back up this claim? Not saying your lying, I'd just 
>> like to know it's true for a fact?
>
> The list of things that trigger the GC is pretty short. See the 
> bottom of this page:
>
> http://dlang.org/garbage.html
>
> Basically, the three things that can do a gc allocation in a 
> built in array are: increasing the length, the ~= and ~ 
> operators, and the [a,b,c] literal syntax.
>
> Slicing, indexing, etc, the other basic operations do not.
>
> If you do: ubyte[] a = (cast(ubyte*) malloc(4)[0..4];, it will 
> compile... and create a slice from the malloced memory. That's 
> one way to create an array without GCing it.
>
>> In that case, am I not essentially just re-creating Array?
>
> Array does a lot of other stuff too... you only really need 
> append and maybe shrink for a static variable, since tracking 
> ownership doesn't matter (it is never disappearing since it is 
> global)

Oh really?!?! I thought slicing used the GC? Is this a recent 
development or always been that way?

ok, so if I just use a shared [], and create it using malloc(as 
you've done above) then release and remalloc when I need to 
append(not efficient but ok in my senario), then it won't use the 
GC?

If so, then I can handle that! I guess [] doesn't have a capacity 
field so I'll have to keep track of that. Other wise, it should 
be pretty simple.

Of course, I still feel like I'm trying to implement array 
because everything turns in to "lots of stuff" at some point ;/




More information about the Digitalmars-d-learn mailing list