Re: Memory leak issue between extern (c) and D function

2023-04-16 Thread Guillaume Piolat via Digitalmars-d-learn
On Friday, 14 April 2023 at 17:31:02 UTC, backtrack wrote: however the memory is not releasing. With the D GC, your object can have three state: - reachable by GC. If D code can see the reference, then it's "alive", kept alive by GC scanning. The GC finds the reference and doesn't touch

Re: Cannot get this C++ example migrated to D

2023-04-16 Thread Skippy via Digitalmars-d-learn
On Sunday, 16 April 2023 at 08:38:55 UTC, Ali Çehreli wrote: On 4/16/23 00:46, Skippy wrote: > I wish D had value type classes as well. That cannot work due to the slicing problem. C++ cannot have value type classes either for the same reason. The difference there is that the enforcement is

Re: Returning a reference to be manipulated

2023-04-16 Thread Dennis via Digitalmars-d-learn
On Saturday, 15 April 2023 at 21:00:01 UTC, kdevel wrote: On Saturday, 15 April 2023 at 15:50:18 UTC, Dennis wrote: [...] care about the type / mutability of the pointer. Returning `i`'s address in a long does not trigger the escape detector: It doesn't care about the type of pointer, but

Re: Cannot get this C++ example migrated to D

2023-04-16 Thread Ali Çehreli via Digitalmars-d-learn
On 4/16/23 00:46, Skippy wrote: > I wish D had value type classes as well. That cannot work due to the slicing problem. C++ cannot have value type classes either for the same reason. The difference there is that the enforcement is by guidelines (e.g. "never pass class objects by value to

Re: Cannot get this C++ example migrated to D

2023-04-16 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 16 April 2023 at 07:46:53 UTC, Skippy wrote: I wish D had value type classes as well. I like the distinction between class and struct in D. It encourages you to think harder about how you intend to use your types. In C++, there may as well only be one or the other; the

Re: Cannot get this C++ example migrated to D

2023-04-16 Thread Skippy via Digitalmars-d-learn
On Sunday, 16 April 2023 at 06:39:17 UTC, Mike Parker wrote: `t1` is default-initialized, so it's null. test t1, t2 = new test(); silly me. I should have picked that up myself. thanks. Ditto for t3. Classes are reference objects, not value objects, so you must explicitly instantiate

Re: Cannot get this C++ example migrated to D

2023-04-16 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 16 April 2023 at 05:58:39 UTC, Skippy wrote: These lines aren't necessary: // ?? int counter; // ?? static this() { counter = test.objCnt; } `t1` is default-initialized, so it's null. test t1, t2 = new test(); Ditto for t3. Classes are reference objects, not value

Cannot get this C++ example migrated to D

2023-04-16 Thread Skippy via Digitalmars-d-learn
Anyone wanna try converting this C++ example to D? (I tried, but getting nowhere.. so far). // --- C++ example - working - #include using std::cout; class test { private: int objNo; static int objCnt; public: test() { objNo = ++objCnt; } ~test() {