Re: A question about postblit constructor

2019-11-06 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Wednesday, 6 November 2019 at 09:19:04 UTC, Jonathan M Davis wrote: DIP: https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1018.md It looks like the release that added copy constructors to the compiler was 2.086 back in May: https://dlang.org/changelog/2.086.0.html https://dlang

Re: A question about postblit constructor

2019-11-06 Thread Jonathan M Davis via Digitalmars-d-learn
it a new malloc'ed address, your memcpy was > >> essentially overwriting the original location with its own > >> data. > > > > What I need was a deep copy, and I thought I could have done it > > using postblit constructor. Thanks for clarification. > >

Re: A question about postblit constructor

2019-11-05 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
to the postblit, the pointer is already pointing at the original location. Without assigning it a new malloc'ed address, your memcpy was essentially overwriting the original location with its own data. What I need was a deep copy, and I thought I could have done it using postblit constructor.

Re: A question about postblit constructor

2019-11-05 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
ithout assigning it a new malloc'ed address, your memcpy was essentially overwriting the original location with its own data. What I need was a deep copy, and I thought I could have done it using postblit constructor. Thanks for clarification. I think copy constructor is less confusing though.

Re: A question about postblit constructor

2019-11-05 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
ithout assigning it a new malloc'ed address, your memcpy was essentially overwriting the original location with its own data. What I need was a deep copy, and I thought I could have done it using postblit constructor. Thanks for clarification.

Re: A question about postblit constructor

2019-11-05 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 5 November 2019 at 10:32:03 UTC, Ferhat Kurtulmuş wrote: On Tuesday, 5 November 2019 at 10:31:05 UTC, Ferhat Kurtulmuş wrote: On Tuesday, 5 November 2019 at 10:13:59 UTC, Mike Parker wrote: [...] Yep, it is obvious that my code is wrong. s1 and s2 point to the same memory address

Re: A question about postblit constructor

2019-11-05 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Tuesday, 5 November 2019 at 10:13:59 UTC, Mike Parker wrote: On Tuesday, 5 November 2019 at 08:47:05 UTC, Ferhat Kurtulmuş wrote: value of int which is 0. I wonder how new memory is allocated without an explicit malloc here. Sorry for this noob question in advance, I could not find any doc

Re: A question about postblit constructor

2019-11-05 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Tuesday, 5 November 2019 at 10:31:05 UTC, Ferhat Kurtulmuş wrote: On Tuesday, 5 November 2019 at 10:13:59 UTC, Mike Parker wrote: [...] Yep, it is obvious that my code is wrong. s1 and s2 point to the same memory address. I could obtain my desired behavior with copy constructor. The docum

Re: A question about postblit constructor

2019-11-05 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 5 November 2019 at 08:47:05 UTC, Ferhat Kurtulmuş wrote: value of int which is 0. I wonder how new memory is allocated without an explicit malloc here. Sorry for this noob question in advance, I could not find any doc mentioning a similar case. int* vals = cast(int*)malloc

A question about postblit constructor

2019-11-05 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
I am trying to learn behavior of postblit constructor. Below code works as expected when I comment out malloc part of postblit constructor. It writes 4 if malloc part of postblit constructor is commented out. Otherwise it writes default init value of int which is 0. I wonder how new memory is

Re: Postblit constructor

2018-03-02 Thread Simen Kjærås via Digitalmars-d-learn
t any postblit constructor called in there, the struct seems just to get copied by a memcpy, can that be? Or is it a bug? Shouldn't the postblit constructor get called there? I'm not sure what you're expecting. The postblit is called when an operation results in there being two

Re: Postblit constructor

2018-03-02 Thread Eduard Staniloiu via Digitalmars-d-learn
On Wednesday, 28 February 2018 at 18:27:49 UTC, Jiyan wrote: On Wednesday, 28 February 2018 at 18:23:04 UTC, Jiyan wrote: Hey, i thought i had understood postblit, but in my Code the following is happening (simplified): struct C { this(this){/*Do sth*/} list!C; void opAssign(const C c) { "P

Re: Postblit constructor

2018-02-28 Thread Jiyan via Digitalmars-d-learn
On Wednesday, 28 February 2018 at 18:23:04 UTC, Jiyan wrote: Hey, i thought i had understood postblit, but in my Code the following is happening (simplified): struct C { this(this){/*Do sth*/} list!C; void opAssign(const C c) { "Postlbit from C called".writeln; // Do sth } } Sry of course

Postblit constructor

2018-02-28 Thread Jiyan via Digitalmars-d-learn
ethods Add, Remove, erase are implemented here ... } The nodes are only allocated over malloc(). So i have to take care of the initioalisation myself. The problem is, that i found out by debugging, that it seems that when i call val.opAssign(op) in constructNodeFrom(), there isnt any postblit c

Re: destructor, postblit constructor --- force calling always

2014-03-31 Thread Benjamin Thaut
Am 31.03.2014 08:06, schrieb monarch_dodra: On Monday, 31 March 2014 at 01:03:22 UTC, Carl Sturtivant wrote: What about destructors, are they always called, or is this another optimization if the struct is in it's default .init state? In any case, there should be 1 destructor call for every ob

Re: destructor, postblit constructor --- force calling always

2014-03-30 Thread monarch_dodra
On Monday, 31 March 2014 at 01:03:22 UTC, Carl Sturtivant wrote: What about destructors, are they always called, or is this another optimization if the struct is in it's default .init state? AFAIK, a destructor is always called when an object goes out of scope... unless, it's being moved out

Re: destructor, postblit constructor --- force calling always

2014-03-30 Thread Carl Sturtivant
D's structs don't have identity. That means, they can be moved without notice at any point in the program. AFAIK the compiler even does that when handling exceptions in a few cases (e.g. with structs on the stack). Having moveable value types allows for a lot of optimizations, both on the compi

Re: destructor, postblit constructor --- force calling always

2014-03-30 Thread Benjamin Thaut
Am 30.03.2014 21:35, schrieb Carl Sturtivant: Context: struct values that are (non-ref) parameters & local variables. Is there a way to arrange that a particular struct's special constructors (postblit,destructor) should always be called even on move, or on destruction of a default initialized

destructor, postblit constructor --- force calling always

2014-03-30 Thread Carl Sturtivant
Context: struct values that are (non-ref) parameters & local variables. Is there a way to arrange that a particular struct's special constructors (postblit,destructor) should always be called even on move, or on destruction of a default initialized value, temporary or not, etcetera, i.e. en