March 18
On Monday, 18 March 2019 at 10:07:37 UTC, Jacob Carlborg wrote:
> On 2019-03-17 12:27, Johannes Pfau wrote:
>> You can implement that using TLS globals, I think this is what
>> std.experimental.allocators theAllocator is supposed to do. Of course
>> you're limited in typing, you can't use templates there.
> Then the functions can't be pure.

Yeah, what you want is either an annotation to tell a function foobar "you're pure except for *these* global variables", and then a way to shim the globals when calling foobar from a pure function, or implicit arguments (which are basically the same thing).
March 18
On Sunday, 17 March 2019 at 14:28:49 UTC, Sjoerd Nijboer wrote:
> I think that this is an example which would be quite easy to learn, not a huge strain on the developers, backwards compatible with existing D code and potentially immensely powerfull. It would also give helpful info which can be used by debuggers and other tooling. One thing it can never do is return an object which was conditionally allocated with one allocator or another.

I'll be honest, the example you gave didn't help me understand your idea at all.

It looks way too complicated, and way too different from D's existing semantics.
March 19
On Saturday, 16 March 2019 at 21:17:02 UTC, Olivier FAURE wrote:
> On Saturday, 16 March 2019 at 20:17:50 UTC, Jacob Carlborg wrote:
>> Instead of having a function allocate memory, pass a buffer, delegate, output range or something similar to the function. Then whatever you pass can decide if it should allocate using the GC, malloc or something else.
> It would have to be a delegate or an output range, because in most cases the callee wouldn't know in advance how much storage it needs to allocate.
> Anyway, it would be pretty nice if there were a standardized way to tell a function how it should allocate its memory;

There is:

void fun(A)(auto ref A allocator);

> it would allow some nice strategies like "I know that I'm going to discard most of what this function allocates, so just put in in a continuous buffer; then deep-copy the relevant data to GC memory, and throw the rest away" (eg in a parser).

This can all be done with a custom allocator, or one built with the building blocks in std.experimental.allocator.

> However, for that to work, you'd probably need a way to pass implicit arguments to a function without having to specify `foobar(defaultGcAllocator, x, y, z)` every time you call a function.

void foobar(int x, int y, int z) {
    import std.experimental.allocator.gc_allocator: GCAllocator;
    foobar(GCAllocator.instance, x, y, z);

void foobar(A)(auto ref A allocator, int x, int y, int z) {
    // ...

Or use `theAllocator`.
Next ›   Last »
1 2 3 4