Re: How to allow +=, -=, etc operators and keep encapsulation?

2021-04-12 Thread evilrat via Digitalmars-d-learn
On Monday, 12 April 2021 at 18:16:14 UTC, Jack wrote: Give this class: ```d class A { int X() { return x; } int X(int v) { return x = v;} private int x; } ``` I'd like to allow use ```+=```, ```-=``` operators on ```X()``` and keep encapsulation. What's a somehow elega

Allocated memory escapes a reference to parameter variable

2021-04-12 Thread Curtis via Digitalmars-d-learn
I recently updated my compiler from 2.091.1 to 2.096.0. After doing so, I started getting deprecations that I think may be related to the DIP25 change mentioned in the release notes here: https://dlang.org/changelog/2.092.0.html#dip25. Here's an example of the code that is generating the depre

Re: GC memory fragmentation

2021-04-12 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 12 April 2021 at 20:50:49 UTC, Per Nordlöw wrote: more aggressive collections when nearing it. What is a more aggressive collection compared to a normal collection? Unfortunately we still have no move support in D's GC because of its impreciseness.

Re: GC memory fragmentation

2021-04-12 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 12 April 2021 at 20:50:49 UTC, Per Nordlöw wrote: I'm surprised there is no such functionality available. It doesn't sound to me like it's that difficult to implement. Afaict, we're looking for a way to call `GC.collect()` when `GC.Status.usedSize` [1] reaches a certain threshold.

Re: GC memory fragmentation

2021-04-12 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 12 April 2021 at 07:03:02 UTC, Sebastiaan Koppe wrote: On side-note, it would also be good if the GC can be aware of the max memory it is allotted so that it knows it needs to do more aggressive collections when nearing it. I'm surprised there is no such functionality available. It

Re: Range Error

2021-04-12 Thread Imperatorn via Digitalmars-d-learn
On Monday, 12 April 2021 at 19:19:12 UTC, kdevel wrote: On Monday, 12 April 2021 at 18:13:38 UTC, Imperatorn wrote: [...] [...] D can be so much fun! ```d import std.stdio; [...] Of course :D

Re: Range Error

2021-04-12 Thread kdevel via Digitalmars-d-learn
On Monday, 12 April 2021 at 18:13:38 UTC, Imperatorn wrote: [...] Yup D can be so much fun! ```d import std.stdio; enum Color {none = " n ", red = " r ", black = " b "}; enum sColor {black= " b ", white= " w "}; class Square { public: this(Color color, sColor Scolor) { this.color

Re: "this" as default parameter for a constructor.

2021-04-12 Thread Jack via Digitalmars-d-learn
On Sunday, 11 April 2021 at 20:38:10 UTC, Pierre wrote: Hi, I have a class with a reference to the parent object and a constructor that has the parent as parameter class foo { this ( foo p /* , other params */ ) { parent = p; } foo parent; } Of cause,

How to allow +=, -=, etc operators and keep encapsulation?

2021-04-12 Thread Jack via Digitalmars-d-learn
Give this class: ```d class A { int X() { return x; } int X(int v) { return x = v;} private int x; } ``` I'd like to allow use ```+=```, ```-=``` operators on ```X()``` and keep encapsulation. What's a somehow elegant way to do that?

Re: Range Error

2021-04-12 Thread Imperatorn via Digitalmars-d-learn
On Monday, 12 April 2021 at 18:01:02 UTC, kdevel wrote: On Sunday, 11 April 2021 at 20:41:35 UTC, Bastiaan Veelo wrote: [...] [...] Yes, there is a `7` where there should be an `i` on this line: ```d for(int i=7;7>=0;i--) ``` This will go on forever, so you get a range error as soon as `i

Re: Range Error

2021-04-12 Thread kdevel via Digitalmars-d-learn
On Sunday, 11 April 2021 at 20:41:35 UTC, Bastiaan Veelo wrote: [...] What am I doing wrong here? Is it the 'for' loop? Yes, there is a `7` where there should be an `i` on this line: ```d for(int i=7;7>=0;i--) ``` This will go on forever, so you get a range error as soon as `i < 0`. Can't

Re: How to use a shared library created in cython?

2021-04-12 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Sunday, 11 April 2021 at 20:08:15 UTC, affonso elias ferreira junior wrote: Hi everyone, I'm trying to use a shared library created in Cython. example. [...] I am on my mobile phone, and cannot reproduce. But i see that this cast(int function()) should be cast(int function(int)). Try cor

Re: "this" as default parameter for a constructor.

2021-04-12 Thread Kagamin via Digitalmars-d-learn
class foo { this ( foo p /* , other params */ ) { parent = p; } foo create() { return new foo(this); } void use() { foo f = create(); } foo parent; }

Re: Range Error

2021-04-12 Thread Ruby The Roobster via Digitalmars-d-learn
On Monday, 12 April 2021 at 01:22:12 UTC, Steven Schveighoffer wrote: On 4/11/21 4:41 PM, Bastiaan Veelo wrote: On Sunday, 11 April 2021 at 19:45:30 UTC, Ruby The Roobster wrote: What am I doing wrong here? Is it the 'for' loop? Yes, there is a `7` where there should be an `i` on this line: `

Re: Range Error

2021-04-12 Thread Ruby The Roobster via Digitalmars-d-learn
On Sunday, 11 April 2021 at 20:41:35 UTC, Bastiaan Veelo wrote: On Sunday, 11 April 2021 at 19:45:30 UTC, Ruby The Roobster wrote: What am I doing wrong here? Is it the 'for' loop? Yes, there is a `7` where there should be an `i` on this line: ```d for(int i=7;7>=0;i--) ``` This will go on

Re: GC memory fragmentation

2021-04-12 Thread Imperatorn via Digitalmars-d-learn
On Sunday, 11 April 2021 at 09:10:22 UTC, tchaloupka wrote: Hi, we're using vibe-d (on Linux) for a long running REST API server and have problem with constantly growing memory until system kills it with OOM killer. [...] Looks like the GC needs some love

Re: GC memory fragmentation

2021-04-12 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Sunday, 11 April 2021 at 09:10:22 UTC, tchaloupka wrote: Hi, we're using vibe-d (on Linux) for a long running REST API server and have problem with constantly growing memory until system kills it with OOM killer. [...] But this is very bad for performance so we've prolonged the interval