Jump to page: 1 215  
Page
Thread overview
Memory allocation purity
May 14, 2014
Brian Schott
May 14, 2014
w0rp
May 15, 2014
Idan Arye
May 15, 2014
Meta
May 15, 2014
Jonathan M Davis
May 14, 2014
Jonathan M Davis
May 15, 2014
Walter Bright
May 15, 2014
Meta
May 15, 2014
Brian Schott
May 15, 2014
Walter Bright
May 15, 2014
Brian Schott
May 15, 2014
Kapps
May 15, 2014
Jonathan M Davis
May 15, 2014
Jonathan M Davis
May 15, 2014
Meta
May 15, 2014
Walter Bright
May 15, 2014
Meta
May 15, 2014
Walter Bright
May 15, 2014
Manu
May 15, 2014
Manu
May 15, 2014
Manu
May 15, 2014
David Nadlinger
May 15, 2014
Adam Sakareassen
May 15, 2014
bearophile
May 15, 2014
David Nadlinger
May 15, 2014
David Nadlinger
May 15, 2014
bearophile
May 15, 2014
Dicebot
May 17, 2014
Jonathan M Davis
May 18, 2014
H. S. Teoh
May 19, 2014
Jonathan M Davis
May 20, 2014
Jonathan M Davis
May 19, 2014
Dicebot
May 19, 2014
Dicebot
May 19, 2014
Dicebot
May 20, 2014
Jonathan M Davis
May 19, 2014
Timon Gehr
May 20, 2014
Jonathan M Davis
May 19, 2014
Jonathan M Davis
May 19, 2014
Jonathan M Davis
May 19, 2014
Jonathan M Davis
May 19, 2014
Jonathan M Davis
May 15, 2014
Timon Gehr
May 15, 2014
Timon Gehr
May 15, 2014
David Nadlinger
May 15, 2014
bearophile
May 15, 2014
Jonathan M Davis
May 15, 2014
Jonathan M Davis
May 15, 2014
Jonathan M Davis
May 15, 2014
luka8088
May 15, 2014
Jonathan M Davis
May 15, 2014
luka8088
May 15, 2014
Don
May 15, 2014
luka8088
May 15, 2014
Don
May 15, 2014
Jonathan M Davis
May 15, 2014
luka8088
May 15, 2014
luka8088
May 15, 2014
Timon Gehr
May 15, 2014
Timon Gehr
May 16, 2014
Peter Alexander
May 15, 2014
luka8088
May 15, 2014
Don
May 15, 2014
bearophile
May 15, 2014
w0rp
May 15, 2014
Timon Gehr
May 15, 2014
Timon Gehr
May 15, 2014
Walter Bright
May 15, 2014
Timon Gehr
May 15, 2014
Walter Bright
May 15, 2014
H. S. Teoh
May 15, 2014
bearophile
May 15, 2014
Walter Bright
May 16, 2014
bearophile
May 16, 2014
Walter Bright
May 16, 2014
Araq
May 16, 2014
Walter Bright
May 16, 2014
bearophile
May 16, 2014
Timon Gehr
May 16, 2014
Timon Gehr
May 17, 2014
Timon Gehr
May 17, 2014
Timon Gehr
May 15, 2014
Walter Bright
May 15, 2014
Walter Bright
May 17, 2014
Jonathan M Davis
May 15, 2014
Marc Schütz
May 15, 2014
bearophile
May 15, 2014
Marc Schütz
May 14, 2014
What is the plan for the "pure"-ity of memory management?

Right now the "new" operator is considered to be pure even though it is not, but related functinos like malloc, GC.addRange, GC.removeRange, and others are not.

This prevents large portions of std.allocator from being pure. This then prevents any containers library built on std.allocator from being pure, which does the same for any funcions and data structures written using those containers.

If malloc can never be considered pure, even when hidden behind an allocator, why can it be considered pure when hidden behind the GC?
May 14, 2014
On Wednesday, 14 May 2014 at 22:42:47 UTC, Brian Schott wrote:
> What is the plan for the "pure"-ity of memory management?
>
> Right now the "new" operator is considered to be pure even though it is not, but related functinos like malloc, GC.addRange, GC.removeRange, and others are not.
>
> This prevents large portions of std.allocator from being pure. This then prevents any containers library built on std.allocator from being pure, which does the same for any funcions and data structures written using those containers.
>
> If malloc can never be considered pure, even when hidden behind an allocator, why can it be considered pure when hidden behind the GC?

I think even C malloc should be considered pure. True, it affects global state by allocating memory, but it never changes existing values, it just allows for new values. free is pure because it isn't side-effecting, it deallocates what you give it. That's just my perspective on it though, others might have other views on it.
May 14, 2014
On Wed, 14 May 2014 22:42:46 +0000
Brian Schott via Digitalmars-d <digitalmars-d@puremagic.com> wrote:

> What is the plan for the "pure"-ity of memory management?
>
> Right now the "new" operator is considered to be pure even though it is not, but related functinos like malloc, GC.addRange, GC.removeRange, and others are not.
>
> This prevents large portions of std.allocator from being pure. This then prevents any containers library built on std.allocator from being pure, which does the same for any funcions and data structures written using those containers.
>
> If malloc can never be considered pure, even when hidden behind an allocator, why can it be considered pure when hidden behind the GC?

I think malloc should definitely be considered pure for the same reasons that new is considered pure. I don't know about the other memory management functions though. I'd really have to think through their side effects to have an opinion on them. If we can make them pure though, that would certainly help with ensuring that allocators can be pure.

- Jonathan M Davis
May 15, 2014
On 5/14/2014 3:42 PM, Brian Schott wrote:
> If malloc can never be considered pure, even when hidden behind an allocator,

It cannot be pure as long as it can fail.

> why can it be considered pure when hidden behind the GC?

Because GC failures are not recoverable, so the pure allocation cannot fail.
May 15, 2014
On Wednesday, 14 May 2014 at 22:42:47 UTC, Brian Schott wrote:
> What is the plan for the "pure"-ity of memory management?
>
> Right now the "new" operator is considered to be pure even though it is not, but related functinos like malloc, GC.addRange, GC.removeRange, and others are not.
>
> This prevents large portions of std.allocator from being pure. This then prevents any containers library built on std.allocator from being pure, which does the same for any funcions and data structures written using those containers.
>
> If malloc can never be considered pure, even when hidden behind an allocator, why can it be considered pure when hidden behind the GC?

Allocating memory through new and malloc should always be pure, I think, because failure either returns null in malloc's case, or throws an error in new's case. As for GC.addRange, GC.removeRange, etc... it's hard to say. These functions definitely alter the state of the GC, but it's all wrapped up in the GC's black box, guaranteed to never escape (I think? I don't know exactly how they're implemented). In the general case, as long as side-effects can be guaranteed to never affect anything outside of a function/class/struct, I think it can probably be pure (D's notion of purity, anyway).
May 15, 2014
On Thursday, 15 May 2014 at 00:00:37 UTC, Walter Bright wrote:
> On 5/14/2014 3:42 PM, Brian Schott wrote:
>> If malloc can never be considered pure, even when hidden behind an allocator,
>
> It cannot be pure as long as it can fail.
>
>> why can it be considered pure when hidden behind the GC?
>
> Because GC failures are not recoverable, so the pure allocation cannot fail.

Malloc is a tricky case. The results it returns are theoretically always unique, and it is referentially transparent if we pretend that we have infinite memory.
May 15, 2014
On Thursday, 15 May 2014 at 00:00:37 UTC, Walter Bright wrote:
> On 5/14/2014 3:42 PM, Brian Schott wrote:
>> If malloc can never be considered pure, even when hidden behind an allocator,
>
> It cannot be pure as long as it can fail.
>
>> why can it be considered pure when hidden behind the GC?
>
> Because GC failures are not recoverable, so the pure allocation cannot fail.

Can we say that Mallocator failures are not recoverable?
May 15, 2014
On 5/14/2014 5:44 PM, Brian Schott wrote:
> Can we say that Mallocator failures are not recoverable?

malloc itself does not have that property. But you could design a wrapper for it that did.
May 15, 2014
On 5/14/2014 5:03 PM, Meta wrote:
> Allocating memory through new and malloc should always be pure, I think, because
> failure either returns null in malloc's case,

malloc cannot be pure if, with the same arguments, it returns null sometimes and not other times.


> or throws an error in new's case.

A non-recoverable error.
  ^^^^^^^^^^^^^^^
May 15, 2014
On Thursday, 15 May 2014 at 00:50:06 UTC, Walter Bright wrote:
> On 5/14/2014 5:03 PM, Meta wrote:
>> Allocating memory through new and malloc should always be pure, I think, because
>> failure either returns null in malloc's case,
>
> malloc cannot be pure if, with the same arguments, it returns null sometimes and not other times.
>
>
>> or throws an error in new's case.
>
> A non-recoverable error.
>   ^^^^^^^^^^^^^^^

If we pretend that there's infinite memory, then malloc will never return null.
« First   ‹ Prev
1 2 3 4 5 6 7 8 9 10 11