On Wednesday, 22 March 2017 at 13:19:32 UTC, Nicholas Wilson
wrote:
On Wednesday, 22 March 2017 at 08:57:34 UTC, ANtlord wrote:
You still have the buffer (the class has to go somewhere!), but
it is implicit (you can't refer to it directly only through the
class reference) and so is the destru
On Wednesday, 22 March 2017 at 08:57:34 UTC, ANtlord wrote:
On Wednesday, 22 March 2017 at 06:47:26 UTC, Ali Çehreli wrote:
On 03/21/2017 09:57 PM, ANtlord wrote:
> Thank you for clarification. But I have one more question. Do
I have to
> use destroy for deallocating object from stack?
Yes beca
On Wednesday, 22 March 2017 at 06:47:26 UTC, Ali Çehreli wrote:
On 03/21/2017 09:57 PM, ANtlord wrote:
> Thank you for clarification. But I have one more question. Do
I have to
> use destroy for deallocating object from stack?
Yes because what is going out of scope are two things:
- A buffer
-
On 03/21/2017 11:47 PM, Ali Çehreli wrote:
> method(false);
> method(true);
> }
>
> Gotta love D for allowing such code but it comes with surprises. Why do
> we suddenly get two destructor calls?
>
> ~this
> ~this
Answering own question: There are two destructor calls because I call
met
On 03/21/2017 09:57 PM, ANtlord wrote:
> On Tuesday, 21 March 2017 at 08:46:43 UTC, Ali Çehreli wrote:
>> Another option is std.conv.emplace:
>>
>> import std.conv : emplace;
>>
>> class MyClass {
>> this(int) @nogc {
>> }
>>
>> ~this() @nogc {
>> }
>> }
>>
>> void method(bool flag
On Tuesday, 21 March 2017 at 12:30:57 UTC, Stefan Koch wrote:
Try scope obj = new MyClass(flag ? 1 : 2);
In essence you should never need to delay construction.
Just construct the object as soon as you have everything to
construct it.
which includes conditions.
Yes I know it. I prepare all
On Tuesday, 21 March 2017 at 08:46:43 UTC, Ali Çehreli wrote:
Another option is std.conv.emplace:
import std.conv : emplace;
class MyClass {
this(int) @nogc {
}
~this() @nogc {
}
}
void method(bool flag) @nogc
{
void[__traits(classInstanceSize, MyClass)] buffer = void;
On Tuesday, 21 March 2017 at 08:08:24 UTC, ANtlord wrote:
Hello! I read documentation about memory management and can't
find description about delay allocation of instance. I have a
method marked by @nogc. This method takes boolean variable. If
this variable is true I want to construct object w
On 03/21/2017 01:08 AM, ANtlord wrote:
void method(bool flag) @nogc
{
scope MyClass obj;
if(flag) {
obj = new MyClass(1);
} else {
obj = new MyClass(2);
}
// using obj
}
Another option is std.conv.emplace:
import std.conv : emplace;
class MyClass {
this
On Tuesday, 21 March 2017 at 08:12:36 UTC, rikki cattermole wrote:
You probably want[0] to allocate a class on the stack instead
of doing this.
[0] http://dlang.org/phobos/std_typecons.html#.scoped
If I will use it I won't use @nogc. Is the only one case?
You probably want[0] to allocate a class on the stack instead of doing this.
[0] http://dlang.org/phobos/std_typecons.html#.scoped
Hello! I read documentation about memory management and can't
find description about delay allocation of instance. I have a
method marked by @nogc. This method takes boolean variable. If
this variable is true I want to construct object with one set of
parameters else I want to construct object
12 matches
Mail list logo