Re: Challenge: Make a data type for holding one of 8 directions allowing increment and overflow

2024-03-13 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 13 March 2024 at 10:27:49 UTC, Basile B. wrote: The semantics of the operators are actually not as clear as that. What if you define ```d enum Direction { N = 1, NE, S = 45, SW } ``` ? Certainly! EnumMembers; can be used. The EnumMembers template from the std.traits

Re: Challenge: Make a data type for holding one of 8 directions allowing increment and overflow

2024-03-13 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 12 March 2024 at 05:38:03 UTC, Liam McGillivray wrote: I am in need of a data type for holding direction information; one of 8 directions on a single axis. They are named in terms of compass directions. If D had a 4-bit datatype, I would just use this and do `+=2` whenever I want

Re: Challenge: Make a data type for holding one of 8 directions allowing increment and overflow

2024-03-12 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 12 March 2024 at 05:38:03 UTC, Liam McGillivray wrote: Perhaps this would be a good programming challenge for someone more experienced than me. Make a data type (probably a struct) for holding one of 8 directional values using 3 bits. It should accept the use of increment operators

Re: Challenge: Make a data type for holding one of 8 directions allowing increment and overflow

2024-03-12 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 13/03/2024 11:00 AM, Liam McGillivray wrote: I'm not familiar with the syntax of the line |value &= 7;|. Is it equivalent to writing |value = value % 7;|? & is a bitwise and. LSB 123456789 MSB & 7 LSB 12300 MSB Anyway, you used an int, but I used an array of 3 bools. I'm guessing

Re: Challenge: Make a data type for holding one of 8 directions allowing increment and overflow

2024-03-12 Thread Liam McGillivray via Digitalmars-d-learn
On Tuesday, 12 March 2024 at 06:38:28 UTC, Richard (Rikki) Andrew Cattermole wrote: By taking advantage of integer wrapping and a bitwise and, its quite a simple problem to solve! Challenge for the reader: add support for binary operations and toString support.

Re: Disable wrilten buf in docker

2024-03-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 12 March 2024 at 06:36:09 UTC, zoujiaqing wrote: Hi, my application use writeln in docker don't display. Python add -u disable it. https://stackoverflow.com/questions/29663459/why-doesnt-python-app-print-anything-when-run-in-a-detached-docker-container Use setvbuf to switch to

Re: Disable wrilten buf in docker

2024-03-12 Thread john rath via Digitalmars-d-learn
I'm glad you find it helpful! If you have any more questions, whether it's about fashion or anything else, feel free to ask. I'm here to assist you with any information or insights you might need.https://vjackets.com/

Re: Disable wrilten buf in docker

2024-03-12 Thread zoujiaqing via Digitalmars-d-learn
On Tuesday, 12 March 2024 at 06:39:40 UTC, Richard (Rikki) Andrew Cattermole wrote: On D's side you can use ``stdout.flush;`` to force it to flush. I don't think there is a way to force flushing via CLI. OK, thank you! Problem solved! Use code: ```D std.stdio.stdout.flush(); ```

Re: Disable wrilten buf in docker

2024-03-12 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On D's side you can use ``stdout.flush;`` to force it to flush. I don't think there is a way to force flushing via CLI.

Re: Challenge: Make a data type for holding one of 8 directions allowing increment and overflow

2024-03-12 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
By taking advantage of integer wrapping and a bitwise and, its quite a simple problem to solve! Challenge for the reader: add support for binary operations and toString support. https://dlang.org/spec/operatoroverloading.html ```d struct Direction { private int value; Direction

Disable wrilten buf in docker

2024-03-12 Thread zoujiaqing via Digitalmars-d-learn
Hi, my application use writeln in docker don't display. Python add -u disable it. https://stackoverflow.com/questions/29663459/why-doesnt-python-app-print-anything-when-run-in-a-detached-docker-container

Challenge: Make a data type for holding one of 8 directions allowing increment and overflow

2024-03-11 Thread Liam McGillivray via Digitalmars-d-learn
I am in need of a data type for holding direction information; one of 8 directions on a single axis. They are named in terms of compass directions. If D had a 4-bit datatype, I would just use this and do `+=2` whenever I want to change the datatype, but it doesn't. Perhaps this would be a

How to use eventcore write an echo server?

2024-03-11 Thread zoujiaqing via Digitalmars-d-learn
I use eventcore latest version write an echo server for test. some error of build. my D code: ```D import eventcore.core; import std.functional : toDelegate; import std.socket : InternetAddress; import std.exception : enforce; import core.time : Duration; import std.stdio : writeln; void

Re: static functions?

2024-03-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, March 11, 2024 10:51:48 AM MDT Andy Valencia via Digitalmars-d- learn wrote: > On Monday, 11 March 2024 at 16:25:13 UTC, Jonathan M Davis wrote: > > ... > > But what exactly static means varies based on the context. > > Thank you for the list! But none of

Re: static functions?

2024-03-11 Thread user1234 via Digitalmars-d-learn
On Monday, 11 March 2024 at 16:51:48 UTC, Andy Valencia wrote: On Monday, 11 March 2024 at 16:25:13 UTC, Jonathan M Davis wrote: ... But what exactly static means varies based on the context. Thank you for the list! But none of those appear to apply to a function defined in the outermost

Re: static functions?

2024-03-11 Thread Andy Valencia via Digitalmars-d-learn
On Monday, 11 March 2024 at 16:25:13 UTC, Jonathan M Davis wrote: ... But what exactly static means varies based on the context. Thank you for the list! But none of those appear to apply to a function defined in the outermost scope of the module. Is static accepted here--but has no actual

Re: static functions?

2024-03-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, March 11, 2024 9:56:24 AM MDT Andy Valencia via Digitalmars-d-learn wrote: > Leveraging my knowledge of C, I assumed a "static" function would > be hidden outside of its own source file. I can't find any > statement about the semantics of a static function in

Re: Recommendation about templating engine library

2024-03-11 Thread Andrea via Digitalmars-d-learn
On Monday, 11 March 2024 at 15:50:28 UTC, bachmeier wrote: I found mustache-d easy enough and good enough for my needs. I haven't used it with a recent compiler, but it's hard to see how it would need much maintenance. just trying it out and kinda fits my needs; the main issues are lack of

Re: Recommendation about templating engine library

2024-03-11 Thread Sergey via Digitalmars-d-learn
On Monday, 11 March 2024 at 15:34:11 UTC, Andrea wrote: There is also diet : https://code.dlang.org/packages/diet-ng Is'nt `diet` specific for HTML / XML structured text ? right. Just mentioned Go library also mostly for HTML generation.

static functions?

2024-03-11 Thread Andy Valencia via Digitalmars-d-learn
Leveraging my knowledge of C, I assumed a "static" function would be hidden outside of its own source file. I can't find any statement about the semantics of a static function in the documentation, and in practice (ldc2 on Linux) it doesn't hide the function? file tst.d: import std.stdio

Re: Recommendation about templating engine library

2024-03-11 Thread bachmeier via Digitalmars-d-learn
On Monday, 11 March 2024 at 14:59:52 UTC, Ferhat Kurtulmuş wrote: You have already mentioned mustache-d. If it compiles with the recent compilers go for it. I used it some time a go for a similar task involving in d code gen. I found mustache-d easy enough and good enough for my needs. I

Re: Recommendation about templating engine library

2024-03-11 Thread Andrea via Digitalmars-d-learn
On Monday, 11 March 2024 at 15:22:39 UTC, Sergey wrote: On Monday, 11 March 2024 at 14:26:01 UTC, Andrea wrote: Opinions ? Many thanks There is also diet : https://code.dlang.org/packages/diet-ng Is'nt `diet` specific for HTML / XML structured text ?

Re: Recommendation about templating engine library

2024-03-11 Thread Sergey via Digitalmars-d-learn
On Monday, 11 March 2024 at 14:26:01 UTC, Andrea wrote: Opinions ? Many thanks There is also diet : https://code.dlang.org/packages/diet-ng

Re: Recommendation about templating engine library

2024-03-11 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Monday, 11 March 2024 at 14:26:01 UTC, Andrea wrote: Hi folks, Working on a side project I have the need to generate text files (mainly D source code) via a templating system. My use case is to have some JSON data populated at runtime from an API and fill-in placeholders in the text with

Recommendation about templating engine library

2024-03-11 Thread Andrea via Digitalmars-d-learn
Hi folks, Working on a side project I have the need to generate text files (mainly D source code) via a templating system. My use case is to have some JSON data populated at runtime from an API and fill-in placeholders in the text with the ability of doing loops over arrays, simple

Re: Need help with Windows linkage ( DMD using ImportC)

2024-03-10 Thread Carl Sturtivant via Digitalmars-d-learn
On Thursday, 7 March 2024 at 18:14:32 UTC, Gregor Mückl wrote: 2. C code referring to MSVC-specific compiler intrinsics. At least InterlockedExchangeAdd, InterlockedExchangeAdd64 and _stosb are such intrinsics. This is harder to resolve. There are two ways forward here: either implement a shim

Re: Can a D library have some types determined by the client program?

2024-03-10 Thread Liam McGillivray via Digitalmars-d-learn
On Sunday, 10 March 2024 at 04:39:33 UTC, Liam McGillivray wrote: https://github.com/LiamM32/Open_Emblem/tree/templates-interfaces I will probably merge it into master soon. I have put up a merge request for these changes I have made to the library and the Raylib front-end. I would be

Re: Can a D library have some types determined by the client program?

2024-03-10 Thread cc via Digitalmars-d-learn
On Saturday, 9 March 2024 at 22:03:34 UTC, Liam McGillivray wrote: Secondly, I found out that interfaces can't have variables. What!? That's crazy! Why wouldn't they? They totally should. Doesn't this mean that I will need to use getter and setter functions instead of direct access when using

Re: DMD windows and Clang's llvm-link.exe

2024-03-09 Thread Carl Sturtivant via Digitalmars-d-learn
On Sunday, 10 March 2024 at 04:22:20 UTC, Richard (Rikki) Andrew Cattermole wrote: On 10/03/2024 4:46 PM, Carl Sturtivant wrote: suggesting that there's a reason version 9 instead of 17 of lld is being used in the latest DMD installation, that may be relevant what I'd like to try. Any idea

Re: Can a D library have some types determined by the client program?

2024-03-09 Thread Liam McGillivray via Digitalmars-d-learn
I have made a new branch of my project called "templates-interfaces" which reworks some things, and turns the Map class into an interface and template. It is now functioning like the master branch, but I think the code should now be (arguably) easier to follow. At least that's true for the

Re: DMD windows and Clang's llvm-link.exe

2024-03-09 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 10/03/2024 4:46 PM, Carl Sturtivant wrote: suggesting that there's a reason version 9 instead of 17 of lld is being used in the latest DMD installation, that may be relevant what I'd like to try. Any idea what that might be? Yes, nobody has updated it.

Re: DMD windows and Clang's llvm-link.exe

2024-03-09 Thread Carl Sturtivant via Digitalmars-d-learn
On Saturday, 9 March 2024 at 22:07:05 UTC, Richard (Rikki) Andrew Cattermole wrote: lld is used and distributed with dmd and ldc. That is known to work. If you have MSVC, it'll prefer that however. Interesting, perhaps I should have known that, though I have not used DMD on Windows for many

How to terminate thread under module destructor?

2024-03-09 Thread An Pham via Digitalmars-d-learn
import core.thread.osthread : Thread; import std.stdio : writeln; __gshared static Thread th; __gshared static size_t tht; void run() { writeln("run"); while (tht == 0) {} } shared static this() { writeln("this"); th = new Thread().start();

Re: DMD windows and Clang's llvm-link.exe

2024-03-09 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 10/03/2024 11:02 AM, Carl Sturtivant wrote: I'd like to see if I can get dmd to work correctly with Clang rather than MS tools. Can anyone share any experience they've had with this or any understanding of the situation? lld is used and distributed with dmd and ldc. That is known to work.

Re: Can a D library have some types determined by the client program?

2024-03-09 Thread Liam McGillivray via Digitalmars-d-learn
Update on two things: One is that I now better understand what it means that D objects are "reference by default". This means that references *can* be null if they are declared with a class. In my commits last night, I have changed many pointers into references. I think my time will be

DMD windows and Clang's llvm-link.exe

2024-03-09 Thread Carl Sturtivant via Digitalmars-d-learn
I'd like to see if I can get dmd to work correctly with Clang rather than MS tools. Can anyone share any experience they've had with this or any understanding of the situation?

Re: Need help with Windows linkage ( DMD using ImportC)

2024-03-09 Thread Carl Sturtivant via Digitalmars-d-learn
On Thursday, 7 March 2024 at 18:14:32 UTC, Gregor Mückl wrote: 1. Missing import libraries for Win32 API functions. Anything starting with `__imp_` is a symbol that should be provided by a DLL import library. MapViewOfFileNuma2 for example is provided by onecore.lib in the Windows SDK,

Re: Why am I getting segfaults when doing `foreach` with arrays of references?

2024-03-09 Thread Liam McGillivray via Digitalmars-d-learn
On Saturday, 9 March 2024 at 07:49:52 UTC, Liam McGillivray wrote: But that begs the question; why? Don't dynamic arrays always start with a length of 0? If the array was only extended when valid objects were appended using the append operator `~=`, and none of those objects were deleted (as I

Re: Why am I getting segfaults when doing `foreach` with arrays of references?

2024-03-09 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 09/03/2024 8:49 PM, Liam McGillivray wrote: But that begs the question; why? Don't dynamic arrays always start with a length of 0? If the array was only extended when valid objects were appended using the append operator |~=|, and none of those objects were deleted (as I the destructor was

Re: Why am I getting segfaults when doing `foreach` with arrays of references?

2024-03-08 Thread Liam McGillivray via Digitalmars-d-learn
On Saturday, 9 March 2024 at 06:37:02 UTC, Richard (Rikki) Andrew Cattermole wrote: Something that I have noticed that you are still doing that was pointed out previously is having a pointer to a class reference. Stuff like ``Tile* currentTile;`` when it should be ``Tile currentTile;`` A

Re: Why am I getting segfaults when doing `foreach` with arrays of references?

2024-03-08 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
Something that I have noticed that you are still doing that was pointed out previously is having a pointer to a class reference. Stuff like ``Tile* currentTile;`` when it should be ``Tile currentTile;`` A class reference is inherently a pointer. So when you checked for nullability in the

Why am I getting segfaults when doing `foreach` with arrays of references?

2024-03-08 Thread Liam McGillivray via Digitalmars-d-learn
With [my game project](https://github.com/LiamM32/Open_Emblem), I have been getting segmentation faults that are unexplainable at my knowledge level. They seem to happen when doing a "foreach" loop through an array of references. Skip to the bolded text if you don't want to read too much, as

Re: Can a D library have some types determined by the client program?

2024-03-08 Thread Liam McGillivray via Digitalmars-d-learn
On Friday, 8 March 2024 at 16:54:48 UTC, cc wrote: If you don't want Unit to be a template, you can just have Map derive from a basic interface or abstract class. You can also have every relevant class share similar templates, you just need to remember to supply the template arguments

Re: Can a D library have some types determined by the client program?

2024-03-08 Thread cc via Digitalmars-d-learn
On Friday, 8 March 2024 at 06:03:51 UTC, Liam McGillivray wrote: A problem I have is that the 3 classes Map, Tile, and Unit reference each-other. If I turn Map into a template, than it complains about the member variable of Unit declared as `Map map;` without arguments. I change this line to

Re: Can a D library have some types determined by the client program?

2024-03-07 Thread Liam McGillivray via Digitalmars-d-learn
On Friday, 8 March 2024 at 03:19:59 UTC, Richard (Rikki) Andrew Cattermole wrote: On 08/03/2024 4:09 PM, Liam McGillivray wrote: Thank you. Is this first example you gave the template? Is the syntax `(ATile : Tile)` saying that ATile must be a derived class of Tile? If this isn't worse in

Re: Can a D library have some types determined by the client program?

2024-03-07 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 08/03/2024 4:09 PM, Liam McGillivray wrote: On Thursday, 7 March 2024 at 22:18:40 UTC, Richard (Rikki) Andrew Cattermole wrote: There are two ways to do this. 1. Use templates. https://tour.dlang.org/tour/en/basics/templates 2. Use a factory function.

Re: Can a D library have some types determined by the client program?

2024-03-07 Thread Liam McGillivray via Digitalmars-d-learn
On Thursday, 7 March 2024 at 22:18:40 UTC, Richard (Rikki) Andrew Cattermole wrote: There are two ways to do this. 1. Use templates. https://tour.dlang.org/tour/en/basics/templates 2. Use a factory function. https://tour.dlang.org/tour/en/basics/delegates ```d class Map(ATile : Tile) {

Re: Can a D library have some types determined by the client program?

2024-03-07 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
There are two ways to do this. 1. Use templates. https://tour.dlang.org/tour/en/basics/templates 2. Use a factory function. https://tour.dlang.org/tour/en/basics/delegates ```d class Map(ATile : Tile) { ATile[] tiles; } ``` Or: ```d class Map { Tile[] tiles; Tile

Can a D library have some types determined by the client program?

2024-03-07 Thread Liam McGillivray via Digitalmars-d-learn
In a source library written in D, is it possible to have some objects, variables, pointers etc which are determined by the program using the library? An example of where this would be useful is in the library I am currently writing. I have a class called `Map`, which holds an array of

Re: Need help with Windows linkage ( DMD using ImportC)

2024-03-07 Thread Gregor Mückl via Digitalmars-d-learn
On Tuesday, 5 March 2024 at 00:20:36 UTC, Carl Sturtivant wrote: On Monday, 4 March 2024 at 21:21:20 UTC, Carl Sturtivant wrote: ``` blah.obj: error LNK2019: unresolved external symbol _mul128 referenced in function MultiplyExtract128 blah.obj: error LNK2019: unresolved external symbol

Re: Hidden members of Class objects

2024-03-07 Thread cc via Digitalmars-d-learn
On Thursday, 7 March 2024 at 00:38:30 UTC, Richard (Rikki) Andrew Cattermole wrote: On 07/03/2024 1:28 PM, Carl Sturtivant wrote: On Wednesday, 6 March 2024 at 23:45:00 UTC, H. S. Teoh wrote: In D, there's a pointer to the vtable and another pointer to a Monitor object (used for synchronized

Re: Hidden members of Class objects

2024-03-06 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 07/03/2024 1:28 PM, Carl Sturtivant wrote: On Wednesday, 6 March 2024 at 23:45:00 UTC, H. S. Teoh wrote: In D, there's a pointer to the vtable and another pointer to a Monitor object (used for synchronized methods).  There was talk about getting rid of the Monitor field years ago, but

Re: Hidden members of Class objects

2024-03-06 Thread kinke via Digitalmars-d-learn
On Thursday, 7 March 2024 at 00:28:17 UTC, Carl Sturtivant wrote: On Wednesday, 6 March 2024 at 23:45:00 UTC, H. S. Teoh wrote: In D, there's a pointer to the vtable and another pointer to a Monitor object (used for synchronized methods). There was talk about getting rid of the Monitor field

Re: Hidden members of Class objects

2024-03-06 Thread Carl Sturtivant via Digitalmars-d-learn
On Wednesday, 6 March 2024 at 23:45:00 UTC, H. S. Teoh wrote: In D, there's a pointer to the vtable and another pointer to a Monitor object (used for synchronized methods). There was talk about getting rid of the Monitor field years ago, but nothing has happened yet. Very interesting: is

Re: Hidden members of Class objects

2024-03-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Mar 06, 2024 at 11:39:13PM +, Carl Sturtivant via Digitalmars-d-learn wrote: > I notice that a class with no data members has a size of two words (at > 64 bits). Presumably there's a pointer to a table of virtual > functions, and one more. Is the Vtable first? [...] > What

Hidden members of Class objects

2024-03-06 Thread Carl Sturtivant via Digitalmars-d-learn
I notice that a class with no data members has a size of two words (at 64 bits). Presumably there's a pointer to a table of virtual functions, and one more. Is the Vtable first? A COM class that inherits from IUnknown and has no data members has a size of three words, presumably as before

Re: chain of exceptions, next method

2024-03-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 6, 2024 6:06:34 AM MST kdevel via Digitalmars-d-learn wrote: > On Saturday, 10 September 2022 at 08:48:39 UTC, Andrej Mitrovic > > wrote: > > [...] > > I wish the compiler would rewrite scope(failure) to use chained > > exceptions. Otherwise a

Re: chain of exceptions, next method

2024-03-06 Thread kdevel via Digitalmars-d-learn
On Saturday, 10 September 2022 at 08:48:39 UTC, Andrej Mitrovic wrote: [...] I wish the compiler would rewrite scope(failure) to use chained exceptions. Otherwise any exceptions thrown within scope(failure) can end up losing information about what was the original exception that was thrown.

Re: Error when using `import`.

2024-03-05 Thread Liam McGillivray via Digitalmars-d-learn
There's something that I'm trying to do that D may or may not be capable of. In the Map class, there is a 2-dimensional array called `grid`, where the Tile objects are stored. The Mission class inherits the Map class. In the Mission class, I want the `grid` array to instead be composed of

Re: Error when using `import`.

2024-03-05 Thread Liam McGillivray via Digitalmars-d-learn
I have made some progress on this. For the raylib front-end, I tried making a class called `Mission` which inherits `Map`. This class handles the graphics, input, and other game events. The program now compiles without errors, and there are some graphics. I have pushed these updates to the

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: Testing membership in associative array

2024-03-04 Thread Profunctor via Digitalmars-d-learn
My sincerest apologies, my initial solution is flawed due to a foolish oversight. The below version works. ```d bool contains(M, K...)(M map, K keys) if (K.length > 0) { static if (K.length == 1) return (keys[0] in map) !is null; else return (keys[0] in map) !is null &&

Re: Testing membership in associative array

2024-03-04 Thread Profunctor via Digitalmars-d-learn
On Monday, 4 March 2024 at 23:49:46 UTC, Lettever wrote: [ ... ] ```d // A template constraint is added to ensure we may always index into `keys`, // in addition to being a sanity check. bool contains(M, K...)(M map, K keys) if (K.length > 0) { static if (K.length == 1) return (keys[0]

Re: Need help with Windows linkage ( DMD using ImportC)

2024-03-04 Thread Carl Sturtivant via Digitalmars-d-learn
On Monday, 4 March 2024 at 21:21:20 UTC, Carl Sturtivant wrote: ``` blah.obj: error LNK2019: unresolved external symbol _mul128 referenced in function MultiplyExtract128 blah.obj: error LNK2019: unresolved external symbol __shiftright128 referenced in function MultiplyExtract128 blah.obj:

Testing membership in associative array

2024-03-04 Thread Lettever via Digitalmars-d-learn
I am trying to create a function that tests membership in nested associative array, however the function I create below, only accepts keys of the same type and if given keys of different types it does not compile, help would be appreciated. This is a example of what Im talking about. ```d

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: New update fix

2024-03-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 2 March 2024 at 09:18:58 UTC, user1234 wrote: On Saturday, 2 March 2024 at 08:41:40 UTC, Salih Dincer wrote: SLM, What exactly did this patch with the new update fix? Nothing, it looks like what happened is that the issue was wrongly referenced by a dlang.org PR

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

Re: Why does disabling a struct's postblit increase its size in memory?

2024-03-03 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 2 March 2024 at 19:29:47 UTC, Per Nordlöw wrote: On Saturday, 2 March 2024 at 19:28:08 UTC, Per Nordlöw wrote: On Saturday, 2 March 2024 at 19:11:42 UTC, kinke wrote: Not according to run.dlang.io, for all available DMD versions. Perhaps your tested `S` was nested in some

Re: Compile-time predicate for checking whether an aggregate field is static

2024-03-02 Thread Per Nordlöw via Digitalmars-d-learn
On Saturday, 2 March 2024 at 19:09:23 UTC, kinke wrote: On Saturday, 2 March 2024 at 15:22:03 UTC, Per Nordlöw wrote: How do I at compile-time check whether an aggregate field is static? https://dlang.org/phobos/std_traits.html#hasStaticMember perhaps. Thanks. Neither my web searches nor

Re: Why does disabling a struct's postblit increase its size in memory?

2024-03-02 Thread Per Nordlöw via Digitalmars-d-learn
On Saturday, 2 March 2024 at 19:28:08 UTC, Per Nordlöw wrote: On Saturday, 2 March 2024 at 19:11:42 UTC, kinke wrote: Not according to run.dlang.io, for all available DMD versions. Perhaps your tested `S` was nested in some function/aggregate and so had an implicit context pointer. Ahh. Yes.

Re: Why does disabling a struct's postblit increase its size in memory?

2024-03-02 Thread Per Nordlöw via Digitalmars-d-learn
On Saturday, 2 March 2024 at 19:11:42 UTC, kinke wrote: Not according to run.dlang.io, for all available DMD versions. Perhaps your tested `S` was nested in some function/aggregate and so had an implicit context pointer. Ahh. Yes. Indeed. My mistake. Thanks.

Re: Why does disabling a struct's postblit increase its size in memory?

2024-03-02 Thread kinke via Digitalmars-d-learn
On Saturday, 2 March 2024 at 15:25:48 UTC, Per Nordlöw wrote: Why does disabling a struct's postblit increase its sizeof by one word? The following holds: ```d struct S { @disable this(this); int _; } struct T { int _; } static assert(S.sizeof == 16); static assert(T.sizeof == int.sizeof);

Re: Compile-time predicate for checking whether an aggregate field is static

2024-03-02 Thread kinke via Digitalmars-d-learn
On Saturday, 2 March 2024 at 15:22:03 UTC, Per Nordlöw wrote: How do I at compile-time check whether an aggregate field is static? https://dlang.org/phobos/std_traits.html#hasStaticMember perhaps.

Why does disabling a struct's postblit increase its size in memory?

2024-03-02 Thread Per Nordlöw via Digitalmars-d-learn
Why does disabling a struct's postblit increase its sizeof by one word? The following holds: ```d struct S { @disable this(this); int _; } struct T { int _; } static assert(S.sizeof == 16); static assert(T.sizeof == int.sizeof); ``` . Why is this needed?

Re: New update fix

2024-03-02 Thread user1234 via Digitalmars-d-learn
On Saturday, 2 March 2024 at 08:41:40 UTC, Salih Dincer wrote: SLM, What exactly did this patch with the new update fix? Nothing, it looks like what happened is that the issue was wrongly referenced by a dlang.org PR

Re: Error when using `import`.

2024-03-01 Thread monkyyy via Digitalmars-d-learn
On Friday, 1 March 2024 at 05:07:24 UTC, Liam McGillivray wrote: I don't know how best to organize the code. So far I have been oo ideas for a 2nd opinion: https://github.com/crazymonkyyy/raylib-2024/blob/master/docs/examplecode.md Theres not a good learning resource but "data oirented

Re: Error when using `import`.

2024-02-29 Thread Liam McGillivray via Digitalmars-d-learn
I now have the Raylib functions working by using `toStrinz`. I pushed some updates to the repository. I made the main project a source library so that I can experiment with different graphics library front-ends. I put have the front-end using Raylib in the `raylib_frontend` directory. It

Re: Bind C++ template specialized with void parameter

2024-02-29 Thread Gregor Mückl via Digitalmars-d-learn
On Thursday, 29 February 2024 at 10:30:59 UTC, DUser wrote: On Wednesday, 28 February 2024 at 22:48:33 UTC, Gregor Mückl wrote: ... But how can I bind Wrapper\ in D? Specifically, how do I even express that template specialization in D syntax? Did you mean any of these? 1. Parameter

Re: Bind C++ template specialized with void parameter

2024-02-29 Thread DUser via Digitalmars-d-learn
On Wednesday, 28 February 2024 at 22:48:33 UTC, Gregor Mückl wrote: ... But how can I bind Wrapper\ in D? Specifically, how do I even express that template specialization in D syntax? Did you mean any of these? 1. Parameter specialization: ```d extern(C++, class): class Wrapper(T) {...}

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: Error when using `import`.

2024-02-28 Thread Danilo via Digitalmars-d-learn
Examples were moved, so it‘s in the same place now: - https://github.com/schveiguy/raylib-d - https://github.com/schveiguy/raylib-d_examples

Bind C++ template specialized with void parameter

2024-02-28 Thread Gregor Mückl via Digitalmars-d-learn
I have roughly the following code in C++ (vastly simplified from reality): ```cpp template class Wrapper { private: T t; bool valid; public: bool isValid() { return valid; } }; template<> class Wrapper\ { private: bool valid; public: bool isValid() { return valid; } }; ``` I can

Re: Error when using `import`.

2024-02-28 Thread Danilo via Digitalmars-d-learn
On Wednesday, 28 February 2024 at 07:56:16 UTC, Liam McGillivray wrote: ``` DrawText("Open Emblem", 180, 300, 64, Colors.RAYWHITE); ``` So why is it that one of these functions, but not the other is allowing D strings in place of C-style strings? C is expecting null-terminated chars. D

Re: Error when using `import`.

2024-02-28 Thread Liam McGillivray via Digitalmars-d-learn
There's something very strange going on when using Raylib-D. I tried using the raylib function `LoadTexture` like this: ``` tileSprites[i] = LoadTexture("../sprites/" ~ spriteName); ``` I got the following error: ``` Error: function `raylib.LoadTexture(const(char)* fileName)` is not callable

Re: Error when using `import`.

2024-02-27 Thread Danilo via Digitalmars-d-learn
On Tuesday, 27 February 2024 at 22:05:48 UTC, Liam McGillivray wrote: Looking at the code examples on the Raylib and SFML website, they look similar in complexity of getting started, but I like it that the Raylib website has lots of simple demonstration programs on the website with the code

Re: Array types and index types

2024-02-27 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 28, 2024 at 03:00:55AM +, Liam McGillivray via Digitalmars-d-learn wrote: > In D, it appears that dynamic arrays (at least by default) use a ulong > as their key type. They are declared like this: > ``` > string[] dynamicArray; > ``` > > I imagine that

Array types and index types

2024-02-27 Thread Liam McGillivray via Digitalmars-d-learn
In D, it appears that dynamic arrays (at least by default) use a ulong as their key type. They are declared like this: ``` string[] dynamicArray; ``` I imagine that using a 64-bit value as the key would be slower than using 32 bits or 16 bits, and 64 bits is way overkill for nearly

Re: Error when using `import`.

2024-02-27 Thread Liam McGillivray via Digitalmars-d-learn
On Tuesday, 27 February 2024 at 03:43:56 UTC, Liam McGillivray wrote: Raylib looks promising. I installed it along with your Raylib-d. I managed to build the example you provided with dub, but trying to use it in it's own dub project in a separate directory isn't working. Just copying and

Re: Error when using `import`.

2024-02-26 Thread Liam McGillivray via Digitalmars-d-learn
On Tuesday, 27 February 2024 at 03:06:19 UTC, Steven Schveighoffer wrote: If you are going for game development, I would recommend raylib-d (https://code.dlang.org/packages/raylib-d), which is my wrapper around the very good raylib library. For doing GUI, raygui is supported, but I also can

Re: Error when using `import`.

2024-02-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 26 February 2024 at 23:27:49 UTC, Liam McGillivray wrote: I don't know whether I should continue this topic or start a new one now that the problem mentioned in the title is fixed. I have now uploaded some of the code to [a GitHub repository](https://github.com/LiamM32/Open_Emblem).

Re: Error when using `import`.

2024-02-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 26 February 2024 at 22:40:49 UTC, Liam McGillivray wrote: On Sunday, 25 February 2024 at 03:23:03 UTC, Paul Backus wrote: You can't give a class the same name as the file it's in. If you do, then when you try to use it from another file, the compiler will get confused and think

Re: Error when using `import`.

2024-02-26 Thread Liam McGillivray via Digitalmars-d-learn
I don't know whether I should continue this topic or start a new one now that the problem mentioned in the title is fixed. I have now uploaded some of the code to [a GitHub repository](https://github.com/LiamM32/Open_Emblem). To make this game usable, I will need a library for graphics and

Re: Error when using `import`.

2024-02-26 Thread Liam McGillivray via Digitalmars-d-learn
On Sunday, 25 February 2024 at 03:23:03 UTC, Paul Backus wrote: You can't give a class the same name as the file it's in. If you do, then when you try to use it from another file, the compiler will get confused and think you're referring to the file instead of the class (that's what "import is

Re: Searching for i" in the forum

2024-02-26 Thread cc via Digitalmars-d-learn
On Sunday, 25 February 2024 at 01:19:15 UTC, Lysander wrote: On Friday, 23 February 2024 at 23:18:12 UTC, kdevel wrote: How do I search for i" in the forum? I get the following errors: i" -> Error: malformed MATCH expression: [i"] (1) i\" -> Error: malformed MATCH expression: [i\"]

Re: need help with simple importC

2024-02-26 Thread Dakota via Digitalmars-d-learn
On Monday, 26 February 2024 at 07:44:02 UTC, Dakota wrote: I am use importC from linux, get this error: ```sh /usr/include/x86_64-linux-gnu/bits/floatn-common.h(214): Error: illegal combination of type specifiers /usr/include/x86_64-linux-gnu/bits/floatn-common.h(251): Error: illegal

Re: importC with gc-sections not work on linux

2024-02-26 Thread Dakota via Digitalmars-d-learn
On Monday, 26 February 2024 at 12:33:02 UTC, Richard (Rikki) Andrew Cattermole wrote: On 27/02/2024 1:28 AM, Dakota wrote: When I use importC to build a c library, there is a lot unused symbol missing. I try add `-L--gc-sections` to dmd to workaround this issue. This removes symbols, not

<    1   2   3   4   5   6   7   8   9   10   >