My humble experience with languages like C++ doesn't really help with understanding how Garbage Collector (if it's because of it, because if I understand correctly, I can imagine memory being de-allocated because we get out of scope of local variable that points to the array, thus there are no more pointers to this memory, thus it gets de-allocated, but we still return reference to this memory, so GC shouldn't really free it?) can cause this - can anyone please explain me what's exactly going on and what would be the proper way to return dynamic array from the function? Thanks in advance.
Returning dynamic array from the function?
SuperPrower via Digitalmars-d-learn Sat, 08 Sep 2018 02:36:01 -0700
I have a function that produces dynamic array of strings. I would
like to return this array from this function. I understand that
dynamic arrays are of reference type, and thus if I try to return
array variable, I will actually return a pointer to the first
element of the array on the heap. Problem is, when I return
dynamic array and try to print it outside of the function, I see
garbage in a first few elements.
- Returning dynamic array from the ... SuperPrower via Digitalmars-d-learn
- Re: Returning dynamic array ... rikki cattermole via Digitalmars-d-learn
- Re: Returning dynamic ar... SuperPrower via Digitalmars-d-learn
- Re: Returning dynami... rikki cattermole via Digitalmars-d-learn
- Re: Returning dy... SuperPrower via Digitalmars-d-learn
- Re: Returni... rjframe via Digitalmars-d-learn