Re: Boneheaded question regarding compilation...

2024-04-02 Thread Dennis via Digitalmars-d-learn
On Tuesday, 2 April 2024 at 18:21:58 UTC, Mike Shah wrote: An easier fix may be perhaps to just use 'dub' and install the glfw dependency. In my talk, I did everything from scratch (my preferred way), though I suspect using dub with glfw-d (https://code.dlang.org/packages/glfw-d) may provide

Re: Boneheaded question regarding compilation...

2024-04-02 Thread Mike Shah via Digitalmars-d-learn
On Monday, 1 April 2024 at 21:23:50 UTC, WhatMeWorry wrote: Huge fan of Mike Shah's YouTube videos regarding D and his latest for D conference: https://mshah.io/conf/24/DConf%20%20Online%202024%20_%20The%20Case%20for%20Graphics%20Programming%20in%20Dlang.pdf So I installed github desktop

Re: Boneheaded question regarding compilation...

2024-04-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 1 April 2024 at 21:23:50 UTC, WhatMeWorry wrote: Huge fan of Mike Shah's YouTube videos regarding D and his latest for D conference: https://mshah.io/conf/24/DConf%20%20Online%202024%20_%20The%20Case%20for%20Graphics%20Programming%20in%20Dlang.pdf So I installed github desktop

Boneheaded question regarding compilation...

2024-04-01 Thread WhatMeWorry via Digitalmars-d-learn
Huge fan of Mike Shah's YouTube videos regarding D and his latest for D conference: https://mshah.io/conf/24/DConf%20%20Online%202024%20_%20The%20Case%20for%20Graphics%20Programming%20in%20Dlang.pdf So I installed github desktop app and cloned his Talks repo. There is a build command

Re: Question on shared memory concurrency

2024-03-05 Thread Andy Valencia via Digitalmars-d-learn
On Monday, 4 March 2024 at 18:08:52 UTC, Andy Valencia wrote: For any other newbie dlang voyagers, here's a version which works as expected using the system memory allocator. On my little i7 I get 1.48 secs wallclock with 5.26 CPU seconds. ... Using a technique I found in a unit test in

Re: Question on shared memory concurrency

2024-03-04 Thread Andy Valencia via Digitalmars-d-learn
On Monday, 4 March 2024 at 16:02:50 UTC, Andy Valencia wrote: On Monday, 4 March 2024 at 03:42:48 UTC, Richard (Rikki) Andrew Cattermole wrote: ... I still hope to be able to share memory between spawned threads, and if it isn't a shared ref of a shared variable, then what would it be? Do I

Re: Question on shared memory concurrency

2024-03-04 Thread evilrat via Digitalmars-d-learn
On Monday, 4 March 2024 at 16:02:50 UTC, Andy Valencia wrote: On Monday, 4 March 2024 at 03:42:48 UTC, Richard (Rikki) Andrew Cattermole wrote: A way to do this without spawning threads manually: ... Thank you! Of course, a thread dispatch per atomic increment is going to be s.l.o.w., so

Re: Question on shared memory concurrency

2024-03-04 Thread Andy Valencia via Digitalmars-d-learn
On Monday, 4 March 2024 at 03:42:48 UTC, Richard (Rikki) Andrew Cattermole wrote: A way to do this without spawning threads manually: ... Thank you! Of course, a thread dispatch per atomic increment is going to be s.l.o.w., so not surprising you had to trim the iterations. Bug I still

Re: Question on shared memory concurrency

2024-03-03 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
A way to do this without spawning threads manually: ```d import std.parallelism : TaskPool, parallel, taskPool, defaultPoolThreads; import std.stdio : writeln; import std.range : iota; enum NSWEPT = 1_000_000; enum NCPU = 4; void main() { import core.atomic : atomicLoad, atomicOp;

Question on shared memory concurrency

2024-03-03 Thread Andy Valencia via Digitalmars-d-learn
I tried a shared memory parallel increment. Yes, it's basically a cache line thrasher, but I wanted to see what's involved in shared memory programming. Even though I tried to follow all the rules to make true shared memory (not thread local) it appears I failed, as the wait loop at the end

question about ctfe init importC zero length array of struct

2024-02-28 Thread Dakota via Digitalmars-d-learn
This is the type defined from c code import by importC: ```c struct A { int count; int[] i; } ``` This kind data need to be init as const to avoid runtime cost, and need to be done from D code. how can I do this ? To put code into D source, I can use "-i=package" to automatically

Re: question

2023-12-13 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 13 December 2023 at 12:49:14 UTC, fred wrote: a bug ? It helps if you explain what you're talking about so we don't have to guess. I tried the code on my computer and it worked fine. But then figuring, you must be saying something doesn't work right, I tried it on another

Re: question

2023-12-13 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 13 December 2023 at 12:49:14 UTC, fred wrote: [...] a bug ? thanks anyway Try to define the flag as static ```d static shared(bool) isDone = false; ``` I dont know if that should be a compiler error to have local shared (I tend to think yes as locals are specific to a frame,

question

2023-12-13 Thread fred via Digitalmars-d-learn
import core.thread; import std.concurrency; import std.stdio : w = writeln; void w2(shared(bool) *done) { while (*done == false) { Thread.sleep(100.msecs); w("print done? ", *done); } } void s2() { shared(bool)

Re: 'typeof' question

2023-11-28 Thread DLearner via Digitalmars-d-learn
On Tuesday, 28 November 2023 at 18:43:37 UTC, Adam D Ruppe wrote: On Tuesday, 28 November 2023 at 18:41:49 UTC, DLearner wrote: A* A_Ptr; struct B { int BFld2; typeof(A_Ptr)[0..($-1)] ASUB; // Idea is ASUB of type A, from A_Ptr of type A*. I think what you really want is

Re: 'typeof' question

2023-11-28 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 28 November 2023 at 18:41:49 UTC, DLearner wrote: A* A_Ptr; struct B { int BFld2; typeof(A_Ptr)[0..($-1)] ASUB; // Idea is ASUB of type A, from A_Ptr of type A*. I think what you really want is typeof(*A_Ptr) ASUB; the typeof thing returns the type you'd get from the

'typeof' question

2023-11-28 Thread DLearner via Digitalmars-d-learn
Trying to manipulate 'typeof' return strings, preferably at compile-time. e.g. to produce struct B below (intended to have an A sub-struct), from A_Ptr alone. ``` struct A { int AFld1; } A* A_Ptr; struct B { int BFld2; typeof(A_Ptr)[0..($-1)] ASUB; // Idea is ASUB of type A, from

Re: Question regarding mir.csv.

2023-11-01 Thread Sergey via Digitalmars-d-learn
On Wednesday, 1 November 2023 at 20:49:16 UTC, Zz wrote: Hi, Currently using std.csv and would like to do the following using mir.csv. auto data = std.csv.csvReader!Layout(input).array; Are there any examples out there on using mir.csv? Regards, Zz you can find some examples in source

Question regarding mir.csv.

2023-11-01 Thread Zz via Digitalmars-d-learn
Hi, Currently using std.csv and would like to do the following using mir.csv. auto data = std.csv.csvReader!Layout(input).array; Are there any examples out there on using mir.csv? Regards, Zz

Re: Question about interface implementation

2023-05-21 Thread Theo via Digitalmars-d-learn
On Sunday, 21 May 2023 at 11:20:30 UTC, ag0aep6g wrote: On 21.05.23 12:55, Theo wrote: As for the other part, if I use an abstract base class, I *must* indicate when i'm overriding the base class method by explicately saying 'override'. I wouldn't mind if implementing interface methods

Re: Question about interface implementation

2023-05-21 Thread ag0aep6g via Digitalmars-d-learn
On 21.05.23 12:55, Theo wrote: As for the other part, if I use an abstract base class, I *must* indicate when i'm overriding the base class method by explicately saying 'override'. I wouldn't mind if implementing interface methods required `override` as well. I don't know if there is a

Re: Question about interface implementation

2023-05-21 Thread Theo via Digitalmars-d-learn
On Sunday, 21 May 2023 at 10:33:07 UTC, ag0aep6g wrote: On 21.05.23 12:28, ag0aep6g wrote: Since @trusted functions are guaranteed (by the programmer) to be safe, they are allowed to overload/implement @safe functions/prototypes. *override oh ok. so i can override a @safe interface method

Re: Question about interface implementation

2023-05-21 Thread ag0aep6g via Digitalmars-d-learn
On 21.05.23 12:28, ag0aep6g wrote: Since @trusted functions are guaranteed (by the programmer) to be safe, they are allowed to overload/implement @safe functions/prototypes. *override

Re: Question about interface implementation

2023-05-21 Thread ag0aep6g via Digitalmars-d-learn
On 21.05.23 11:55, Theo wrote: class MerchantShip : Ship {     private int speed = 0; // If only I had 'private(this)' !!     // how do I know this method is actually an implementation of an interface method     // and not a method specific to this class?     // AND ... how come I can

Question about interface implementation

2023-05-21 Thread Theo via Digitalmars-d-learn
see comments in the code below. they are my questions. But feel free to ignore the comment about 'private(this)' ;-) interface Ship { @safe void setSpeed(int speed); @safe int getSpeed(); } class PirateShip : Ship { private int speed = 0; // If only I had 'private(this)' !!

Re: quick question, probably of little importance...

2023-04-30 Thread Cecil Ward via Digitalmars-d-learn
On Monday, 1 May 2023 at 03:53:24 UTC, Cecil Ward wrote: On Wednesday, 26 April 2023 at 23:07:39 UTC, WhatMeWorry wrote: [...] Correction: I can’t count. There are only two instructions in parallel with another pair running alongside, not three. The first reg, reg move counts as zero

Re: quick question, probably of little importance...

2023-04-30 Thread Cecil Ward via Digitalmars-d-learn
On Wednesday, 26 April 2023 at 23:07:39 UTC, WhatMeWorry wrote: On Wednesday, 26 April 2023 at 23:02:07 UTC, Richard (Rikki) Andrew Cattermole wrote: Don't forget ``num % 2 == 0``. None should matter, pretty much all production compilers within the last 30 years should recognize all forms of

Re: quick question, probably of little importance...

2023-04-26 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 27/04/2023 11:07 AM, WhatMeWorry wrote: On Wednesday, 26 April 2023 at 23:02:07 UTC, Richard (Rikki) Andrew Cattermole wrote: Don't forget ``num % 2 == 0``. None should matter, pretty much all production compilers within the last 30 years should recognize all forms of this and do the right

Re: quick question, probably of little importance...

2023-04-26 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Apr 26, 2023 at 11:07:39PM +, WhatMeWorry via Digitalmars-d-learn wrote: > On Wednesday, 26 April 2023 at 23:02:07 UTC, Richard (Rikki) Andrew > Cattermole wrote: > > Don't forget ``num % 2 == 0``. > > > > None should matter, pretty much all production compilers within the > > last

Re: quick question, probably of little importance...

2023-04-26 Thread WhatMeWorry via Digitalmars-d-learn
On Wednesday, 26 April 2023 at 23:02:07 UTC, Richard (Rikki) Andrew Cattermole wrote: Don't forget ``num % 2 == 0``. None should matter, pretty much all production compilers within the last 30 years should recognize all forms of this and do the right thing. Thanks. Fastest reply ever! And I

Re: quick question, probably of little importance...

2023-04-26 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
Don't forget ``num % 2 == 0``. None should matter, pretty much all production compilers within the last 30 years should recognize all forms of this and do the right thing.

quick question, probably of little importance...

2023-04-26 Thread WhatMeWorry via Digitalmars-d-learn
I just need an even/odd functionality. Don't think D has a built-in operator. // Found this C code online. int isEven(int num) { return !(num & 1); } // found this in std.functional.unaryFun alias isEven = unaryFun!("(a & 1) == 0"); assert(isEven(2) && !isEven(1)); If

Re: (Noob question) Should subclasses be defined in separate modules?

2023-01-12 Thread Mike Parker via Digitalmars-d-learn
On Friday, 13 January 2023 at 05:17:59 UTC, thebluepandabear wrote: (Sorry if this is a duplicate.) If I have the following code inside of a module: ```D class Obj { private { string name = "Hi"; } } class ObjDerived : Obj { } ``` Is it best practice to define `ObjDerived`

(Noob question) Should subclasses be defined in separate modules?

2023-01-12 Thread thebluepandabear via Digitalmars-d-learn
(Sorry if this is a duplicate.) If I have the following code inside of a module: ```D class Obj { private { string name = "Hi"; } } class ObjDerived : Obj { } ``` Is it best practice to define `ObjDerived` inside another module, since `ObjDerived` can still access the

Re: auto scope question?

2022-10-25 Thread WhatMeWorry via Digitalmars-d-learn
typeof(screen.output.findSplit("")) s; Perfect. That was the "essence" of my question. But thanks to Ali, I don't have to use such esoteric syntax. D is a wonderful language, but I seem to shoot myself in the foot :)

Re: auto scope question?

2022-10-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/25/22 6:07 PM, WhatMeWorry wrote: I'm naturally getting a undefined identifier `s` error in the return. Is there some way to refactor my code?  I tried to declare s outside of the else brackets like: auto screen = executeShell(cmdLine); auto s; ... {     s =

Re: auto scope question?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 15:07, WhatMeWorry wrote: > auto screen = executeShell(cmdLine); > auto s; That can't work because there is no information to infer the type of 's'. Judging from the return type of getPath, perhaps it's string[]: string[] s; This is the question we should answer first

auto scope question?

2022-10-25 Thread WhatMeWorry via Digitalmars-d-learn
I'm naturally getting a undefined identifier `s` error in the return. Is there some way to refactor my code? I tried to declare s outside of the else brackets like: auto screen = executeShell(cmdLine); auto s; ... { s = screen.output.findSplit("REG_SZ"); } but that doesn't compile

Re: Design question regarding saving changes in the original array and/or returning a new set

2022-10-23 Thread matheus via Digitalmars-d-learn
On Sunday, 23 October 2022 at 17:36:25 UTC, Paul Backus wrote: On Sunday, 23 October 2022 at 13:32:44 UTC, matheus wrote: ... You say your idea is "like passing some argument", so why not actually pass an argument? For example: ... Hi, thanks for the example, and yes I'd like to do that,

Re: Design question regarding saving changes in the original array and/or returning a new set

2022-10-23 Thread matheus via Digitalmars-d-learn
On Sunday, 23 October 2022 at 16:16:55 UTC, Sergey wrote: On Sunday, 23 October 2022 at 15:47:27 UTC, matheus wrote: Hi H. S. Teoh, I think you misunderstood my question, since English is not my first language maybe this was a problem from my part, but anyway, I'm not talking about "

Re: Design question regarding saving changes in the original array and/or returning a new set

2022-10-23 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 23 October 2022 at 13:32:44 UTC, matheus wrote: I have a design question and I'd like to hear some advice. Let's say that I want to create a method to sort an array: arr.sort(asc); I think usually this would usually return a new set of that array but now sorted. But If I

Re: Design question regarding saving changes in the original array and/or returning a new set

2022-10-23 Thread Sergey via Digitalmars-d-learn
On Sunday, 23 October 2022 at 15:47:27 UTC, matheus wrote: Hi H. S. Teoh, I think you misunderstood my question, since English is not my first language maybe this was a problem from my part, but anyway, I'm not talking about "sort" from main library. This example was if I had d

Re: Design question regarding saving changes in the original array and/or returning a new set

2022-10-23 Thread matheus via Digitalmars-d-learn
Hi H. S. Teoh, I think you misunderstood my question, since English is not my first language maybe this was a problem from my part, but anyway, I'm not talking about "sort" from main library. This example was if I had designed my "own version". Matheus.

Re: Design question regarding saving changes in the original array and/or returning a new set

2022-10-23 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Oct 23, 2022 at 01:32:44PM +, matheus via Digitalmars-d-learn wrote: > Hi, > > I have a design question and I'd like to hear some advice. Let's say > that I want to create a method to sort an array: > > arr.sort(asc); > > I think usually this would

Design question regarding saving changes in the original array and/or returning a new set

2022-10-23 Thread matheus via Digitalmars-d-learn
Hi, I have a design question and I'd like to hear some advice. Let's say that I want to create a method to sort an array: arr.sort(asc); I think usually this would usually return a new set of that array but now sorted. But If I want to do this in the original, I think I would do

Re: Real simple question... for good programmers

2022-10-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/22/22 5:53 PM, WhatMeWorry wrote: string[] tokens = userSID.output.split!isWhite; writeln("tokens = ", tokens); tokens = ["SID", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",

Re: Real simple question... for good programmers

2022-10-22 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 22 October 2022 at 21:53:05 UTC, WhatMeWorry wrote: string[] tokens = userSID.output.split!isWhite; writeln("tokens = ", tokens); [...] Is there a clever way that I can discard all the extra null strings in the resultant string array? Easiest way is to use [`filter`][1].

Re: Real simple question... for good programmers

2022-10-22 Thread Daniel via Digitalmars-d-learn
On Saturday, 22 October 2022 at 22:01:09 UTC, Enjoys Math wrote: On Saturday, 22 October 2022 at 21:53:05 UTC, WhatMeWorry wrote: string[] tokens = userSID.output.split!isWhite; writeln("tokens = ", tokens); tokens = ["SID", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",

Re: Real simple question... for good programmers

2022-10-22 Thread Enjoys Math via Digitalmars-d-learn
__MWE Code:__ ``` module DlangForumsMWE; import std.stdio; import std.algorithm.mutation; int main() { //string[] tokens = userSID.output.split!isWhite; //writeln("tokens = ", tokens); auto tokens = ["SID", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",

Re: Real simple question... for good programmers

2022-10-22 Thread Ali Çehreli via Digitalmars-d-learn
On 10/22/22 14:53, WhatMeWorry wrote: > > > string[] tokens = userSID.output.split!isWhite; > writeln("tokens = ", tokens); Could you please show minimal compilable code that demonstrates the issue. I spent some time with some guesses but failed (to get my code to compile with

Re: Real simple question... for good programmers

2022-10-22 Thread Enjoys Math via Digitalmars-d-learn
On Saturday, 22 October 2022 at 21:53:05 UTC, WhatMeWorry wrote: string[] tokens = userSID.output.split!isWhite; writeln("tokens = ", tokens); tokens = ["SID", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",

Real simple question... for good programmers

2022-10-22 Thread WhatMeWorry via Digitalmars-d-learn
string[] tokens = userSID.output.split!isWhite; writeln("tokens = ", tokens); tokens = ["SID", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",

Re: probably a trivial question...

2022-10-13 Thread rassoc via Digitalmars-d-learn
On 10/14/22 01:43, WhatMeWorry via Digitalmars-d-learn wrote: Does D provide any guidance as to what is preferred or are they identical for all intents and purposes? You won't see a difference for this specific example since the split function supports character, string and even range

Re: probably a trivial question...

2022-10-13 Thread Ali Çehreli via Digitalmars-d-learn
Changing the order of lines... On 10/13/22 16:43, WhatMeWorry wrote: > return s.split(';'); // single quotes That one is a single character and very lightweigth because it's just an integral value. You can't put more than one character within single quotes: ';x' // ERROR > return

probably a trivial question...

2022-10-13 Thread WhatMeWorry via Digitalmars-d-learn
I was a little (nicely) surprised that I could use double quotes, single quotes, or back ticks in the following line of code. return s.split(";"); // double quotes or return s.split(';'); // single quotes or return s.split(`;`); // back ticks Does D provide any guidance as to what is

Re: Question on shapes

2022-05-18 Thread JG via Digitalmars-d-learn
On Tuesday, 17 May 2022 at 00:10:55 UTC, Alain De Vos wrote: Let's say a shape is ,a circle with a radius ,or a square with a rectangular size. I want to pass shapes to functions, eg to draw them on the screen, draw(myshape) or myshape.draw(); But how do i implement best shapes ? You could

Re: Question on shapes

2022-05-17 Thread Dom Disc via Digitalmars-d-learn
On Tuesday, 17 May 2022 at 09:30:12 UTC, forkit wrote: On Tuesday, 17 May 2022 at 04:37:58 UTC, Ali Çehreli wrote: In you OOP example, I am curious why you chose Shape to be an interface, rather than a base class. You can inherit from multiple interfaces, but only from one base class. So

Re: Question on shapes

2022-05-17 Thread Ali Çehreli via Digitalmars-d-learn
On 5/17/22 02:30, forkit wrote: > On Tuesday, 17 May 2022 at 04:37:58 UTC, Ali Çehreli wrote: >> > > In you OOP example, I am curious why you chose Shape to be an interface, > rather than a base class. I always have the same question. :) interface feels lighterweight, so i

Re: Question on shapes

2022-05-17 Thread forkit via Digitalmars-d-learn
On Tuesday, 17 May 2022 at 04:37:58 UTC, Ali Çehreli wrote: In you OOP example, I am curious why you chose Shape to be an interface, rather than a base class.

Re: Question on shapes

2022-05-17 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 17 May 2022 at 05:08:30 UTC, matheus wrote: In D there would be a better way to do such thing? Nothing really specific to D, but for one or two properties, you might just add them as function parameters with default values: ```d void draw(float scale = 1.0f); ``` If you have

Re: Question on shapes

2022-05-17 Thread bauss via Digitalmars-d-learn
On Tuesday, 17 May 2022 at 00:10:55 UTC, Alain De Vos wrote: Let's say a shape is ,a circle with a radius ,or a square with a rectangular size. I want to pass shapes to functions, eg to draw them on the screen, draw(myshape) or myshape.draw(); But how do i implement best shapes ? In addition

Re: Question on shapes

2022-05-17 Thread Ali Çehreli via Digitalmars-d-learn
On 5/16/22 22:08, matheus wrote: > interface Shape { >void draw(); >void draw(float scale); > } Interfaces can have 'final' functions: interface Shape { void draw(float scale); final void draw() { draw(1); } } Obviously, for that to work, now Circle.draw() etc. required to

Re: Question on shapes

2022-05-16 Thread matheus via Digitalmars-d-learn
but I have a question, in your second example, let's say that sometimes it would be required to "draw" with some scale factor, so (As a newbie) I would do something like this: interface Shape { void draw(); void draw(float scale); } Then in Circle class: void draw(float scale) {

Re: Question on shapes

2022-05-16 Thread Ali Çehreli via Digitalmars-d-learn
On 5/16/22 17:10, Alain De Vos wrote: Let's say a shape is ,a circle with a radius ,or a square with a rectangular size. I want to pass shapes to functions, eg to draw them on the screen, draw(myshape) or myshape.draw(); But how do i implement best shapes ? There are many ways of achieving

Question on shapes

2022-05-16 Thread Alain De Vos via Digitalmars-d-learn
Let's say a shape is ,a circle with a radius ,or a square with a rectangular size. I want to pass shapes to functions, eg to draw them on the screen, draw(myshape) or myshape.draw(); But how do i implement best shapes ?

Re: Beginner memory question.

2022-04-19 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 19, 2022 at 05:01:15PM +, Era Scarecrow via Digitalmars-d-learn wrote: [...] > In linux using zram i've allocated and made a compressed drive of 8Gb > which took only 200k of space [...] All unallocated pages are assumed > null/zero filled, and if you zeroize a block it will

Re: Beginner memory question.

2022-04-19 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 16 April 2022 at 20:48:15 UTC, Adam Ruppe wrote: On Saturday, 16 April 2022 at 20:41:25 UTC, WhatMeWorry wrote: Is virtual memory entering into the equation? Probably. Memory allocated doesn't physically exist until written to a lot of the time. This might be very much an OS

Re: Beginner memory question.

2022-04-19 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 19, 2022 at 12:54:06PM +, bauss via Digitalmars-d-learn wrote: > On Saturday, 16 April 2022 at 20:48:15 UTC, Adam Ruppe wrote: > > On Saturday, 16 April 2022 at 20:41:25 UTC, WhatMeWorry wrote: > > > Is virtual memory entering into the equation? > > > > Probably. Memory allocated

Re: Beginner memory question.

2022-04-19 Thread bauss via Digitalmars-d-learn
On Saturday, 16 April 2022 at 20:48:15 UTC, Adam Ruppe wrote: On Saturday, 16 April 2022 at 20:41:25 UTC, WhatMeWorry wrote: Is virtual memory entering into the equation? Probably. Memory allocated doesn't physically exist until written to a lot of the time. You can also exceed your RAM in

Re: Beginner memory question.

2022-04-16 Thread Adam Ruppe via Digitalmars-d-learn
On Saturday, 16 April 2022 at 20:41:25 UTC, WhatMeWorry wrote: Is virtual memory entering into the equation? Probably. Memory allocated doesn't physically exist until written to a lot of the time.

Beginner memory question.

2022-04-16 Thread WhatMeWorry via Digitalmars-d-learn
I'm playing around with dynamic arrays and I wrote the tiny program (at bottom). I get the following output: PS C:\D\sandbox> dmd -m64 maxMem.d PS C:\D\sandbox> .\maxMem.exe Reserving 1,610,613,245 elements reserve() returned a size of: 1,610,613,245 The capacity() of big is 1,610,613,245

Re: Basic question about size_t and ulong

2022-03-22 Thread Era Scarecrow via Digitalmars-d-learn
On Wednesday, 23 March 2022 at 00:51:42 UTC, Era Scarecrow wrote: On Tuesday, 22 March 2022 at 21:23:43 UTC, H. S. Teoh wrote: We already have this: import std.conv : to; int x; long y; y = x.to!long; // equivalent to straight assignment / cast x =

Re: Basic question about size_t and ulong

2022-03-22 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 22 March 2022 at 21:23:43 UTC, H. S. Teoh wrote: On Tue, Mar 22, 2022 at 09:11 PM, Era Scarecrow wrote: [...] I'd almost wish D had a more lenient mode and would do automatic down-casting, then complain if it *would* have failed to downcast data at runtime. [...] We already

Re: Basic question about size_t and ulong

2022-03-22 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 22, 2022 at 09:11:00PM +, Era Scarecrow via Digitalmars-d-learn wrote: [...] > I'd almost wish D had a more lenient mode and would do automatic > down-casting, then complain if it *would* have failed to downcast data > at runtime. [...] We already have this: import

Re: Basic question about size_t and ulong

2022-03-22 Thread Era Scarecrow via Digitalmars-d-learn
ned as the default? This question is probably going off topic but still be interesting to know if there's an answer. > Is it better to use int, long, size_t? D uses size_t for automatic indexes during foreach, and as I said, it makes sense to me. Otherwise, I think the go-to type should be int for

Re: Basic question about size_t and ulong

2022-03-22 Thread Ali Çehreli via Digitalmars-d-learn
On 3/22/22 11:28, Era Scarecrow wrote: > So when should you use size_t? I use size_t for anything that is related to count, index, etc. However, this is a contested topic because size_t is unsigned. As soon as you use it in an expression, the whole expression becomes unsigned as well.

Re: Basic question about size_t and ulong

2022-03-22 Thread Era Scarecrow via Digitalmars-d-learn
() so that we can seek() to an earlier place and ulong for tell(). Perhaps we should back up and ask a different question. I've been working on adaptation of Reed Solomon Codes, and i keep getting thrown with casting errors, to the point where i just want to make everything size_t to make

Re: Basic question about size_t and ulong

2022-03-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/18/22 7:01 PM, Ali Çehreli wrote: On 3/18/22 14:54, WhatMeWorry wrote: > size_t huge = uint.max;  // compiles That means size_t is uint on that build. Not that Ali is wrong in the full sense, but this line alone will compile on both 64 and 32-bit systems, so it is not informative.

Re: Basic question about size_t and ulong

2022-03-18 Thread Ali Çehreli via Digitalmars-d-learn
On 3/18/22 14:54, WhatMeWorry wrote: > size_t is an alias to one of the unsigned integral basic types, and > represents a type that is large enough to represent an offset into all > addressable memory. In practice, that general description means "size_t is either ulong or uint" depending on

Re: Basic question about size_t and ulong

2022-03-18 Thread Adam Ruppe via Digitalmars-d-learn
On Friday, 18 March 2022 at 21:54:55 UTC, WhatMeWorry wrote: Isn't ulong an integer? And isn't memory addresses 64 bits long? Only if you are doing a 64 bit build. Try using -m64

Basic question about size_t and ulong

2022-03-18 Thread WhatMeWorry via Digitalmars-d-learn
Quoting the D documentation: size_t is an alias to one of the unsigned integral basic types, and represents a type that is large enough to represent an offset into all addressable memory. And I have a line of code: size_t huge = ulong.max; dmd GC.d GC.d(29): Error: cannot implicitly

Re: Embarrassed to ask this question because it seems so trivial but genuinely curious...

2022-01-27 Thread H. S. Teoh via Digitalmars-d-learn
to type qualifiers before the function > definitions "this" (like a return type?) and the output was exactly > identical. So I guess my question is, is this just a matter of > esthetics or is some more nuanced goal at work here? In method declarations, modifiers like const/imm

Re: Embarrassed to ask this question because it seems so trivial but genuinely curious...

2022-01-27 Thread Steven Schveighoffer via Digitalmars-d-learn
eturn type?) and the output was  exactly identical.  So I guess my question is, is this just a matter of esthetics or is some more nuanced goal at work here? For constructors, being on the front is not misleading. But for a member function that returns a value, take a look: ```d struct S { int * x;

Re: Embarrassed to ask this question because it seems so trivial but genuinely curious...

2022-01-27 Thread Dennis via Digitalmars-d-learn
On Thursday, 27 January 2022 at 17:42:09 UTC, WhatMeWorry wrote: So I guess my question is, is this just a matter of esthetics or is some more nuanced goal at work here? It doesn't matter much for constructors, but in general, the problem with placing qualifiers in front is that it looks

Embarrassed to ask this question because it seems so trivial but genuinely curious...

2022-01-27 Thread WhatMeWorry via Digitalmars-d-learn
s were placed after the function parameter list (int i). Just for fun, I moved to type qualifiers before the function definitions "this" (like a return type?) and the output was exactly identical. So I guess my question is, is this just a matter of esthetics or is some more nuanced goal at work here?

Re: Linkage question

2022-01-24 Thread duser via Digitalmars-d-learn
On Monday, 24 January 2022 at 19:41:30 UTC, frame wrote: On Monday, 24 January 2022 at 18:30:02 UTC, Stanislav Blinov wrote: The difference is in how arguments are being passed, which you seem to have discovered already :) Would like to know where the linkage format is defined, thx. It

Re: Linkage question

2022-01-24 Thread Paul Backus via Digitalmars-d-learn
On Monday, 24 January 2022 at 19:41:30 UTC, frame wrote: It claims that the D calling convention matches C. But it seems that the arguments are pushed in order whereas C does it in reverse order and the -218697648 value is indeed my 3rd string pointer. Windows has two calling conventions for

Re: Linkage question

2022-01-24 Thread frame via Digitalmars-d-learn
On Monday, 24 January 2022 at 18:30:02 UTC, Stanislav Blinov wrote: The difference is in how arguments are being passed, which you seem to have discovered already :) Would like to know where the linkage format is defined, thx. It should be here: https://dlang.org/spec/abi.html although

Re: Linkage question

2022-01-24 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 24 January 2022 at 17:23:01 UTC, frame wrote: I understand that the linkage must match but besides the name mangling, what's happen here? What is the difference if I remove the `extern (C)` part from the T alias? The difference is in how arguments are being passed, which you seem

Linkage question

2022-01-24 Thread frame via Digitalmars-d-learn
If I declare a function as extern(C) inside a DLL, I have also to cast the function pointer as extern(C) or it fails calling, eg. ```d // --- my.dll export extern (C) void log(int mode, string a, string b, string c) { /* stuff */ } // --- main.d alias T = extern (C) void function(int,

Re: map question

2022-01-23 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 23 January 2022 at 09:38:57 UTC, Siarhei Siamashka wrote: On Sunday, 23 January 2022 at 09:08:46 UTC, Stanislav Blinov wrote: Using `iota` here incurs additional computation and argument copies that are actually never used, i.e. wasted work. So I'd say go with `generate`, as that

Re: map question

2022-01-23 Thread Siarhei Siamashka via Digitalmars-d-learn
On Sunday, 23 January 2022 at 09:08:46 UTC, Stanislav Blinov wrote: Using `iota` here incurs additional computation and argument copies that are actually never used, i.e. wasted work. So I'd say go with `generate`, as that seems the intent. Isn't this normally a compiler's job to eliminate

Re: map question

2022-01-23 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 22 January 2022 at 23:54:27 UTC, forkit wrote: On Saturday, 22 January 2022 at 19:55:43 UTC, Stanislav Blinov wrote: thanks for the explanation. That really helped :-) writeln( generate!(() => dice(0.6, 1.4)).take(howManyTimes) ); [1, 1, 1, 1, 0] (or after reading Ali's

Re: map question

2022-01-22 Thread forkit via Digitalmars-d-learn
On Saturday, 22 January 2022 at 19:55:43 UTC, Stanislav Blinov wrote: thanks for the explanation. That really helped :-) writeln( generate!(() => dice(0.6, 1.4)).take(howManyTimes) ); [1, 1, 1, 1, 0] (or after reading Ali's response - getting rid of rnd, and using _ ) writeln(

Re: map question

2022-01-22 Thread Ali Çehreli via Digitalmars-d-learn
On 1/22/22 11:32, forkit wrote: > trying to make sense of the below: The generate() solution shown by Stanislav Blinov is suitable here. > auto rnd = Random(unpredictableSeed); Somebody else mentioned this before but none of the programs we've seen so far seemed to need a special random

Re: map question

2022-01-22 Thread Stanislav Blinov via Digitalmars-d-learn
same as above line? //writeln(howManyTimes.iota.map!(5 => rnd.dice(0.6, 1.4)).format!"%(%s,%)"); } // --- No, it's not the same. 'Tis not really a "map question", looks more like a question about https://dlang.org/spec/expression.html#function_literals (see #10).

map question

2022-01-22 Thread forkit via Digitalmars-d-learn
trying to make sense of the below: // --- module test; import std; void main() { auto rnd = Random(unpredictableSeed); int howManyTimes = 5; // ok - using 'e =>' makes sense writeln(howManyTimes.iota.map!(e => rnd.dice(0.6, 1.4)).format!"%(%s,%)"); // ok - though

Re: -debug question

2022-01-20 Thread forkit via Digitalmars-d-learn
On Friday, 21 January 2022 at 02:10:34 UTC, Steven Schveighoffer wrote: thanks Steven (and Ali too).

Re: -debug question

2022-01-20 Thread Ali Çehreli via Digitalmars-d-learn
On 1/20/22 18:07, forkit wrote: I have a line of code, that I do NOT want executed when -debug is passed in. enforce(!exists(fname), "Oop! That file already exists!"); Is this even possible? (with using -version ..) The following should do it: debug {} else { foo(); } Ali

Re: -debug question

2022-01-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/20/22 9:07 PM, forkit wrote: I have a line of code, that I do NOT want executed when -debug is passed in. enforce(!exists(fname), "Oop! That file already exists!"); Is this even possible? (with using -version ..) `debug` is like a `version` block. ```d debug {} else { // code that

  1   2   3   4   5   6   7   8   9   10   >