April 26, 2017
On Tuesday, 25 April 2017 at 22:21:33 UTC, Ali Çehreli wrote:
> On 04/25/2017 01:20 PM, jmh530 wrote:
> > [...]
> numbers, allocate
> > [...]
> to free the
> > [...]
>
> Yes.
>
> > [...]
> freed by D
> > [...]
>
> Correct.
>
> > [...]
> of just the
> > [...]
> C++ smart
> > [...]
> totally grok it
> > [...]
>
> Just by guessing, what we don't see here is that there is a wrapping layer that does the copying. Disposal logic is called by that layer. So, your scope(exit) takes place at a higher layer. Here is made-up-pseudo-code by me. :)
>
> TypeForExcel wrapper_actually_called_by_excel(/* ... */) {
>     /* ... */
>
>     double[] ret_from_your_function = FuncReturnArrayNoGc(/* ... */);
>     scope (exit) disposal_function(ret_from_your_function);
>
>     TypeForExcel arg_to_excel = copy_for_excel(ret_from_your_function);
>     return arg_to_excel;
> }
>
> Ali

Yep, that's pretty much what happens, except that the `scope(exit)` is inside a `static if` that checks for the presence of `@Dispose`.

Atila
April 27, 2017
On Tuesday, 25 April 2017 at 20:20:08 UTC, jmh530 wrote:
> On Monday, 24 April 2017 at 21:59:34 UTC, Atila Neves wrote:
>>
>> Enter the `@Dispose` UDA:
>>
>
> I found this really interesting.
>
> Am I understanding the process correctly: apply map to numbers, allocate and return a new array in D, copy it to Excel, call dispose to free the D memory.
>
> So if you instead used something like
> scope(exit) Mallocator.instance.dispose(dArg);
> then Excel wouldn't be able to use it because it would be freed by D already?
>
> It seems like your @Dispose UDA could have many uses outside of just the excel-d package. If I understand correctly, it's similar to C++ smart pointers, but not exactly the same. I'm still not sure I totally grok it though.

I considered using the smart pointers from my automem package but didn't want to add a dependency. I'm thinking now I could make it optional and if it detects that your function returns Unique!T it can convert the wrapped T to an Excel type.

Atila
1 2 3
Next ›   Last »