Re: Is this the proper way to do it?

2021-02-12 Thread mw via Digitalmars-d-learn
On Saturday, 13 February 2021 at 05:52:34 UTC, Jack wrote: I have a base class A, where I make specific operator depending on the derived class type. Currently I'm using something like this: c is a class derived from A bool shouldDoX = (cast(X)c) !is null || (cast(Y)c) !is null || (cast(K)c)

Is this the proper way to do it?

2021-02-12 Thread Jack via Digitalmars-d-learn
I have a base class A, where I make specific operator depending on the derived class type. Currently I'm using something like this: c is a class derived from A bool shouldDoX = (cast(X)c) !is null || (cast(Y)c) !is null || (cast(K)c) !is null ... ; as the number of cast(C) !is null is growin

Re: how to properly compare this type?

2021-02-12 Thread Jack via Digitalmars-d-learn
helpful always,thank you guys

Re: Trying to reduce memory usage

2021-02-12 Thread Ali Çehreli via Digitalmars-d-learn
On 2/11/21 6:22 PM, H. S. Teoh wrote: >bool[size_t] hashes; I would start with an even simpler solution until it's proven that there still is a memory issue: import std.stdio; void main() { bool[string] lines; foreach (line; stdin.byLine) { if (line !in li

Re: vibe.d json deserializeJson!Foo and ddbc.update!Foo

2021-02-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/12/21 6:22 PM, Chris Bare wrote: I'm working on a project with vibe.d and ddbc to access my database. Both have powerful functions that operate on Struct types to avoid a lot of boilerplate code. I have a web site that sends a json message to update a record. deserializeJson creates a new

Re: GC.addRange in pure function

2021-02-12 Thread Petar via Digitalmars-d-learn
On Friday, 12 February 2021 at 12:17:13 UTC, Per Nordlöw wrote: On Tuesday, 9 February 2021 at 03:05:10 UTC, frame wrote: On Sunday, 7 February 2021 at 14:13:18 UTC, vitamin wrote: Why using 'new' is allowed in pure functions but calling GC.addRange or GC.removeRange isn't allowed? Would maki

vibe.d json deserializeJson!Foo and ddbc.update!Foo

2021-02-12 Thread Chris Bare via Digitalmars-d-learn
I'm working on a project with vibe.d and ddbc to access my database. Both have powerful functions that operate on Struct types to avoid a lot of boilerplate code. I have a web site that sends a json message to update a record. deserializeJson creates a new Foo record containing the json data. Ho

Re: GC.addRange in pure function

2021-02-12 Thread Petar via Digitalmars-d-learn
On Friday, 12 February 2021 at 19:48:01 UTC, vitamin wrote: On Wednesday, 10 February 2021 at 16:25:44 UTC, Petar Kirov [ZombineDev] wrote: On Wednesday, 10 February 2021 at 13:44:53 UTC, vit wrote: [...] TL;DR Yes, you can, but it depends on what "without problem" means for you :P [...]

Re: GC.addRange in pure function

2021-02-12 Thread vitamin via Digitalmars-d-learn
On Wednesday, 10 February 2021 at 16:25:44 UTC, Petar Kirov [ZombineDev] wrote: On Wednesday, 10 February 2021 at 13:44:53 UTC, vit wrote: [...] TL;DR Yes, you can, but it depends on what "without problem" means for you :P [...] Thanks, Yes, I am implementing container (ref counted point

Re: Trying to reduce memory usage

2021-02-12 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Feb 12, 2021 at 07:23:12AM +, frame via Digitalmars-d-learn wrote: > On Friday, 12 February 2021 at 02:22:35 UTC, H. S. Teoh wrote: > > > This turns the OP's O(n log n) algorithm into an O(n) algorithm, > > doesn't need to copy the entire content of the file into memory, and > > also u

Re: Profiling

2021-02-12 Thread James Blachly via Digitalmars-d-learn
On 2/9/21 12:45 AM, JG wrote: I was trying to profile a d program. So I ran: dub build --build=profile. I then ran the program and it produced trace.log and trace.def. I then ran d-profile-viewer and got the following error: std.conv.ConvException@/home/jg/dlang/ldc-1.24.0/bin/../import/std/co

Re: GC.addRange in pure function

2021-02-12 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 9 February 2021 at 03:05:10 UTC, frame wrote: On Sunday, 7 February 2021 at 14:13:18 UTC, vitamin wrote: Why using 'new' is allowed in pure functions but calling GC.addRange or GC.removeRange isn't allowed? Would making `new T[]` inject a call to `GC.addRange` based on `T` (and ma

Re: Trying to reduce memory usage

2021-02-12 Thread frame via Digitalmars-d-learn
On Friday, 12 February 2021 at 07:23:12 UTC, frame wrote: On Friday, 12 February 2021 at 02:22:35 UTC, H. S. Teoh wrote: This turns the OP's O(n log n) algorithm into an O(n) algorithm, doesn't need to copy the entire content of the file into memory, and also uses much less memory by storing