digitalmars.D - Encouraging memory efficiency
- Tero (13/13) Jul 17 2014 Just watched Don's DConf 2014 talk where he said D has to be
- Kapps (8/21) Jul 17 2014 In theory there would probably be an allocator that uses alloca
- bearophile (6/11) Jul 17 2014 Perhaps once the "scope" (and memory lifetimes) is fleshed out,
- Jacob Carlborg (5/8) Jul 17 2014 It is still available and no sign of deprecation (except everyone saying...
- Dicebot (2/10) Jul 17 2014 "Discouraged and unmaintained" is probably a better description.
- Jacob Carlborg (4/5) Jul 17 2014 How does it need maintaining?
- Dicebot (4/8) Jul 18 2014 I mean that if you create bug report or enhancement request for
- bearophile (6/9) Jul 17 2014 See:
- John Colvin (9/22) Jul 18 2014 When talking about allocations:
- Timon Gehr (11/23) Jul 18 2014 Well, there is always this hack:
- Nick Treleaven (2/4) Jul 21 2014 alloca(T.sizeof * size)
- Walter Bright (2/11) Jul 21 2014 You might be interested in std.internal.scopebuffer.
Just watched Don's DConf 2014 talk where he said D has to be ruthless about memory inefficiency. Here's one thing that I think could help avoid unnecessary garbage: built-in syntax for this: import core.stdc.stdlib : alloca; ubyte[] buffer = (cast(ubyte*) alloca(bufsize)) [0 .. bufsize]; Often bufsize is not known at compile-time but it won't change after the buffer allocation. So there's no reason to create garbage other than the *inconvenience* of using alloca. Allocating in the stack seems ideal so I'd encourage that by a clean syntax. I keep missing this feature.
Jul 17 2014
On Thursday, 17 July 2014 at 16:28:00 UTC, Tero wrote:Just watched Don's DConf 2014 talk where he said D has to be ruthless about memory inefficiency. Here's one thing that I think could help avoid unnecessary garbage: built-in syntax for this: import core.stdc.stdlib : alloca; ubyte[] buffer = (cast(ubyte*) alloca(bufsize)) [0 .. bufsize]; Often bufsize is not known at compile-time but it won't change after the buffer allocation. So there's no reason to create garbage other than the *inconvenience* of using alloca. Allocating in the stack seems ideal so I'd encourage that by a clean syntax. I keep missing this feature.In theory there would probably be an allocator that uses alloca when Andrei's std.allocator makes it in. Using alloca is actually rather problematic in D right now though (with DMD at least)... https://issues.dlang.org/show_bug.cgi?id=12820 Also, there used to be a built in syntax, 'scope foo = new Foo()' that would allocate on the stack, but that's deprecated now (and seemed to segfault when I tried it).
Jul 17 2014
Kapps:In theory there would probably be an allocator that uses alloca when Andrei's std.allocator makes it in.How is it going to work?Also, there used to be a built in syntax, 'scope foo = new Foo()' that would allocate on the stack, but that's deprecated nowPerhaps once the "scope" (and memory lifetimes) is fleshed out, it will be un-deprecated :-) Bye, bearophile
Jul 17 2014
On 2014-07-17 18:35, Kapps wrote:Also, there used to be a built in syntax, 'scope foo = new Foo()' that would allocate on the stack, but that's deprecated now (and seemed to segfault when I tried it).It is still available and no sign of deprecation (except everyone saying that). -- /Jacob Carlborg
Jul 17 2014
On Thursday, 17 July 2014 at 19:41:57 UTC, Jacob Carlborg wrote:On 2014-07-17 18:35, Kapps wrote:"Discouraged and unmaintained" is probably a better description.Also, there used to be a built in syntax, 'scope foo = new Foo()' that would allocate on the stack, but that's deprecated now (and seemed to segfault when I tried it).It is still available and no sign of deprecation (except everyone saying that).
Jul 17 2014
On 17/07/14 22:18, Dicebot wrote:"Discouraged and unmaintained" is probably a better description.How does it need maintaining? -- /Jacob Carlborg
Jul 17 2014
On Friday, 18 July 2014 at 06:46:16 UTC, Jacob Carlborg wrote:On 17/07/14 22:18, Dicebot wrote:I mean that if you create bug report or enhancement request for scope classes it is quite unlikely anyone will pay attention to it."Discouraged and unmaintained" is probably a better description.How does it need maintaining?
Jul 18 2014
Tero:Allocating in the stack seems ideal so I'd encourage that by a clean syntax. I keep missing this feature.See: https://issues.dlang.org/show_bug.cgi?id=9832 http://en.cppreference.com/w/cpp/container/dynarray Bye, bearophile
Jul 17 2014
On Thursday, 17 July 2014 at 16:28:00 UTC, Tero wrote:Just watched Don's DConf 2014 talk where he said D has to be ruthless about memory inefficiency. Here's one thing that I think could help avoid unnecessary garbage: built-in syntax for this: import core.stdc.stdlib : alloca; ubyte[] buffer = (cast(ubyte*) alloca(bufsize)) [0 .. bufsize]; Often bufsize is not known at compile-time but it won't change after the buffer allocation. So there's no reason to create garbage other than the *inconvenience* of using alloca. Allocating in the stack seems ideal so I'd encourage that by a clean syntax. I keep missing this feature.When talking about allocations: The stack is just a fixed size chunk of pre-allocated memory with complicated rules and caveats for use. It's only advantage as a place for general purpose allocation is that it's "hot" memory, i.e. it's normally already in cache due to it's locality. The fact that it is 1) pre-allocated and 2) eagerly de-allocates on exiting a function can be easily implemented in any allocation scheme.
Jul 18 2014
On 07/17/2014 06:27 PM, Tero wrote:Just watched Don's DConf 2014 talk where he said D has to be ruthless about memory inefficiency. Here's one thing that I think could help avoid unnecessary garbage: built-in syntax for this: import core.stdc.stdlib : alloca; ubyte[] buffer = (cast(ubyte*) alloca(bufsize)) [0 .. bufsize]; Often bufsize is not known at compile-time but it won't change after the buffer allocation. So there's no reason to create garbage other than the *inconvenience* of using alloca. Allocating in the stack seems ideal so I'd encourage that by a clean syntax. I keep missing this feature.Well, there is always this hack: import core.stdc.stdlib : alloca; auto createBuffer(T,alias size)(T[] buf=(cast(T*)alloca(size))[0..size]){ return buf; } void main(){ auto bufsize=5; auto buffer=createBuffer!(ubyte,bufsize); import std.stdio; writeln(buffer); }
Jul 18 2014
On 19/07/2014 01:31, Timon Gehr wrote:auto createBuffer(T,alias size)(T[] buf=(cast(T*)alloca(size))[0..size]){ return buf; }alloca(T.sizeof * size)
Jul 21 2014
On 7/17/2014 9:27 AM, Tero wrote:Just watched Don's DConf 2014 talk where he said D has to be ruthless about memory inefficiency. Here's one thing that I think could help avoid unnecessary garbage: built-in syntax for this: import core.stdc.stdlib : alloca; ubyte[] buffer = (cast(ubyte*) alloca(bufsize)) [0 .. bufsize]; Often bufsize is not known at compile-time but it won't change after the buffer allocation. So there's no reason to create garbage other than the *inconvenience* of using alloca. Allocating in the stack seems ideal so I'd encourage that by a clean syntax. I keep missing this feature.You might be interested in std.internal.scopebuffer.
Jul 21 2014