DasBetterR

bachmeier no at spam.net
Fri Jul 7 20:33:08 UTC 2023


On Friday, 30 June 2023 at 16:14:48 UTC, jmh530 wrote:
> On Thursday, 29 June 2023 at 23:51:44 UTC, bachmeier wrote:
>> [snip]
>
> Glad you're continuing to do work on this front. There's a lot 
> of great material explaining things, which is always good.
>
> It would be cool to have another version of the link below for 
> using a mir Slice with R.
> https://bachmeil.github.io/betterr/setvar.html

I was wrong. They added custom allocators a while back, but 
didn't tell anyone.

Actually, what I said before is technically correct. The SEXP 
struct itself still has to be allocated by R and managed by the R 
garbage collector. It's just that you can use a custom allocator 
to send a pointer to the data you've allocated, and once R is 
done with the data, it'll call the function you've provide to 
free the memory before destroying the SEXP struct that wraps it.

I uploaded [an example 
here](https://github.com/bachmeil/betterr/blob/main/testing/testalloc.d).

It's still a bit hackish because you need to adjust the pointer 
for a header R inserts when it allocates arrays. Adjusting by 
10*double.sizeof works in this example, but "my test didn't 
segfault" doesn't exactly inspire confidence. Once I am 
comfortable with this solution, I'll do a new release of betterr.

This'll be kind of a big deal if it works. For instance, if you 
want to use a database interface and D doesn't have one, you can 
use R's interface to that database without having R manage your 
project's memory. You could use any of the available R interfaces 
(databases, machine learning libraries, Qt, etc.)


More information about the Digitalmars-d-announce mailing list