On Friday, 11 September 2015 at 21:48:14 UTC, Prudence wrote:
Oh really?!?! I thought slicing used the GC? Is this a recent development or always been that way?

Always been that way. A D slice is just a C pointer + length packed together. A slice simply increments the pointer and/or decrements the length - no allocation needed.

GC can make slices more convenient, since you don't need to think about who owns that memory you're slicing to free it, but that's true of pointers and references and everything too.

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?

yeah.

you might want to GC.addRange it though so the contents are scanned anyway...

(btw the garbage collector is actually pretty nice, why are you avoiding it anyway?)

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

Nope but you can just use realloc which does track some capacity for you. (Actually, the built-in ~= operator does that too, just with the GC instead of the C function. It sometimes won't reallocate because it knows it already has enough capacity. Read more here: http://dlang.org/d-array-article.html )


  • Re: shared array? Kagamin via Digitalmars-d-learn
    • Re: shared array? Prudence via Digitalmars-d-learn
      • Re: shared array? Kagamin via Digitalmars-d-learn
        • Re: shared array... Prudence via Digitalmars-d-learn
          • Re: shared a... Adam D. Ruppe via Digitalmars-d-learn
            • Re: sha... Prudence via Digitalmars-d-learn
              • Re:... Adam D. Ruppe via Digitalmars-d-learn
              • Re:... Prudence via Digitalmars-d-learn
              • Re:... Adam D. Ruppe via Digitalmars-d-learn
              • Re:... Laeeth Isharc via Digitalmars-d-learn
              • Re:... Jonathan M Davis via Digitalmars-d-learn
              • Re:... Prudence via Digitalmars-d-learn
              • Re:... Laeeth Isharc via Digitalmars-d-learn
              • Re:... Adam D. Ruppe via Digitalmars-d-learn
              • Re:... Adam D. Ruppe via Digitalmars-d-learn
              • Re:... Laeeth Isharc via Digitalmars-d-learn
              • Re:... Jonathan M Davis via Digitalmars-d-learn
              • Re:... ponce via Digitalmars-d-learn
              • Re:... Ola Fosheim Grøstad via Digitalmars-d-learn

Reply via email to