digitalmars.D - New feature in git-head: Uniform construction for built-in types
- Andrej Mitrovic (10/10) Mar 07 2014 https://github.com/D-Programming-Language/dmd/pull/1356 was recently
- Remo (7/19) Mar 07 2014 Every time I see something like this in C++, I see bad C++ and I
- bearophile (5/9) Mar 07 2014 "new int(1)" allocates on the GC-managed heap, and no memory
- Dicebot (4/8) Mar 07 2014 "new" always means heap memory allocation, this is the very point
- Dicebot (5/17) Mar 07 2014 I like it as it simplifies some generic code by providing uniform
https://github.com/D-Programming-Language/dmd/pull/1356 was recently merged (pull by Kenji), implementing this enhancement: https://d.puremagic.com/issues/show_bug.cgi?id=9112 Example code: ----- int n = int(1); int *p = new int(1); assert(*p == 1); ----- I'm just curious what people think about the new feature. Discuss!
Mar 07 2014
On Friday, 7 March 2014 at 11:41:41 UTC, Andrej Mitrovic wrote:https://github.com/D-Programming-Language/dmd/pull/1356 was recently merged (pull by Kenji), implementing this enhancement: https://d.puremagic.com/issues/show_bug.cgi?id=9112 Example code: ----- int n = int(1); int *p = new int(1); assert(*p == 1); ----- I'm just curious what people think about the new feature. Discuss!Every time I see something like this in C++, I see bad C++ and I see memory leaks :) But how is this handle in D2, is this real memory allocation in the second example? Probably no? How about struct, are there any changes about constructors? I hope yes.
Mar 07 2014
Remo:Every time I see something like this in C++, I see bad C++ and I see memory leaks :) But how is this handle in D2, is this real memory allocation in the second example? Probably no?"new int(1)" allocates on the GC-managed heap, and no memory leaks should happen. Bye, bearophile
Mar 07 2014
On Friday, 7 March 2014 at 12:09:48 UTC, Remo wrote:But how is this handle in D2, is this real memory allocation in the second example? Probably no?"new" always means heap memory allocation, this is the very point of using it.How about struct, are there any changes about constructors? I hope yes.It is irrelevant to the linked change.
Mar 07 2014
On Friday, 7 March 2014 at 11:41:41 UTC, Andrej Mitrovic wrote:https://github.com/D-Programming-Language/dmd/pull/1356 was recently merged (pull by Kenji), implementing this enhancement: https://d.puremagic.com/issues/show_bug.cgi?id=9112 Example code: ----- int n = int(1); int *p = new int(1); assert(*p == 1); ----- I'm just curious what people think about the new feature. Discuss!I like it as it simplifies some generic code by providing uniform construction syntax. Not the silver bullet though, as you still can't do `auto t2 = T(t1)` for classes (without static opCall). But definitely can save on some `statif if`s.
Mar 07 2014