Re: bool passed by ref, safe or not ?

2024-06-04 Thread Olivier Pisano via Digitalmars-d-learn
On Wednesday, 5 June 2024 at 05:15:42 UTC, Olivier Pisano wrote: This is technically not a memory corruption, because as bool.sizeof < int.sizeof, you just write the low order byte of an int you allocated on the stack. It was not an int, it was a ushort. Anyway, what I wrote still applies.

Re: bool passed by ref, safe or not ?

2024-06-04 Thread Olivier Pisano via Digitalmars-d-learn
On Tuesday, 4 June 2024 at 16:58:50 UTC, Basile B. wrote: question in the header, code in the body, execute on a X86 or X86_64 CPU I understand that the notion of `bool` doesn't exist on X86, hence what will be used is rather an instruction that write on the lower 8 bits, but with a 7 bits

Re: How best to implement items and weapons in my RPG. Nested classes? Delegates?

2024-04-04 Thread Olivier Pisano via Digitalmars-d-learn
Hi, You should have a look at the decorator design pattern, it reduces the amount of classes to implement if you need to combine different effects such as elemental damage to your weapons (e.g. if you want flame arrows). https://en.wikipedia.org/wiki/Decorator_pattern

Re: length's type.

2024-01-28 Thread Olivier Pisano via Digitalmars-d-learn
On Sunday, 28 January 2024 at 08:55:54 UTC, zjh wrote: On Sunday, 28 January 2024 at 06:34:13 UTC, Siarhei Siamashka wrote: The explicit conversion `.length.to!int` has an extra benefit I rarely use numbers over one million. But do I have to consider numbers over `4 billion` every day?

Re: Is sizeof() available in D language?

2023-09-04 Thread Olivier Pisano via Digitalmars-d-learn
On Monday, 4 September 2023 at 09:41:54 UTC, BoQsc wrote: I've seen everyone using **datatype**`.sizeof` property. https://dlang.org/spec/property.html#sizeof It's great, but I wonder if it differ in any way from the standard C function `sizeof()`. Technically speaking, in C, sizeof is not

Connecting to D-Bus signals

2022-10-04 Thread Olivier Pisano via Digitalmars-d-learn
Hi, I am currently trying to connect to a signal on UDisks2 to be notified whenever the user plugs a USB drive on the system, but my method never gets called. Here is my code : import ddbus; import ddbus.c_lib; import std.stdio; final class UsbDevice { void

Re: How to get rid of "nothrow" ?

2020-05-17 Thread Olivier Pisano via Digitalmars-d-learn
On Sunday, 17 May 2020 at 09:27:40 UTC, Vinod K Chandran wrote: Hi all, I am trying to create a win32 based gui in dlang. So far so good. I can create and display my window on screen. But for handling messages, i planned to write something like message crackers in c++. But since, my WndProc

Re: XMM Intrinsics

2020-05-09 Thread Olivier Pisano via Digitalmars-d-learn
On Friday, 8 May 2020 at 12:38:51 UTC, Marcio Martins wrote: Hi, I am building a CRC32C implementation using SSE for D, because I couldn't find any readily available :[ Here is mine: https://github.com/opisano/crc32c/blob/master/crc32c.d

Re: Idomatic way to guarantee to run destructor?

2020-05-04 Thread Olivier Pisano via Digitalmars-d-learn
On Monday, 4 May 2020 at 09:20:06 UTC, Ali Çehreli wrote: On 4/30/20 10:04 AM, Ben Jones wrote:> On Thursday, 30 April 2020 at 16:55:36 UTC, Robert M. Münch wrote: > I think you want to use scope rather than auto which will put the class > on the stack and call its destructor: >

Re: How do I extract and convert datatypes from ResultRange

2019-08-26 Thread Olivier Pisano via Digitalmars-d-learn
On Monday, 26 August 2019 at 13:49:21 UTC, Anders S wrote: Hi guys, I'm trying to read a post of different datatypes from MariaDB table into another message and pass it on into a FIFO pipe to an other application. My code : string sql = "SELECT * FROM guirequest WHERE read_request =

Re: How to ensure string compatibility In D?

2019-01-22 Thread Olivier Pisano via Digitalmars-d-learn
On Tuesday, 22 January 2019 at 13:55:30 UTC, FrankLike wrote: Hi,everyone, In C++, _T can guarantee that when converting from ascii encoding type to unicode encoding type, the program does not need to be modified. What do I need to do in D? Thanks. Hi, _T is not relevant to C++, but to

Re: Recommended coding convention for combining unix and windows code ?

2016-06-08 Thread Olivier Pisano via Digitalmars-d-learn
Hi, I personally separate OS-specific implementations in modules with the same name, in different directories. From the filesystem perspective: widget.d linux/widgetimpl.d windows/widgetimpl.d From the code perspective, the *impl modules would present homonymic types with the same public

Re: D equivalent of C++ bind ?

2016-05-10 Thread Olivier Pisano via Digitalmars-d-learn
Salut Christophe, Did you have a look at https://dlang.org/phobos/std_functional.html#partial ?

Re: How about use Gc as a big memory pool?

2016-04-07 Thread Olivier Pisano via Digitalmars-d-learn
On Friday, 8 April 2016 at 03:27:04 UTC, Dsby wrote: when the soft start, call GC.disable(). use "new " create a class , struct or a array. and use destory(T/void *) to call the ~this(), then GC.free to free the memory, and use RAII in class or Struct. And user the Timer, or in some where to

Re: nogc Array

2016-01-26 Thread Olivier Pisano via Digitalmars-d-learn
On Tuesday, 26 January 2016 at 05:53:29 UTC, Igor wrote: On Tuesday, 26 January 2016 at 04:38:13 UTC, Adam D. Ruppe wrote: On Tuesday, 26 January 2016 at 04:31:07 UTC, Igor wrote: then std.algorithm.find!("a.myInt == b")(classes, 3) Try std.algorithm.find!("a.myInt == b")(classes[], 3)

Re: static array crashes my program

2015-12-05 Thread Olivier Pisano via Digitalmars-d-learn
On Saturday, 5 December 2015 at 09:49:06 UTC, ref2401 wrote: I want to create a static array large enough to store 1MB of float values. What am I doing wrong? Here is a sample code with notes: void main(string[] args) { enum size_t COUNT = 1024 * 512 / float.sizeof; // works OK :)

Re: `clear`ing a dynamic array

2015-10-25 Thread Olivier Pisano via Digitalmars-d-learn
On Sunday, 25 October 2015 at 04:04:29 UTC, Shriramana Sharma wrote: rsw0x wrote: use std.container.array Thanks all for all the recommendations. When would one use std.array.appender with a built-in array vs std.container.array.Array? What are the pros and cons on either side? Appender

Re: Reading and converting binary file 2 bits at a time

2015-08-27 Thread Olivier Pisano via Digitalmars-d-learn
On Thursday, 27 August 2015 at 09:38:52 UTC, Andrew Brown wrote: That's lovely, thank you. One quick question, the length of the file is not a multiple of the length of ubyte, but the cast still seems to work. Do you know how it converts a truncated final section? Thanks again Andrew

Re: Arrays of structs

2015-08-27 Thread Olivier Pisano via Digitalmars-d-learn
On Thursday, 27 August 2015 at 10:49:02 UTC, John Burton wrote: To be honest I'm finding it very hard to find the right idioms in D for safe and efficient programming when I'm so used to C++ / RAII everywhere. I'll adapt though :P This is true for every new language you learn. You first

Re: Concatenates int

2014-07-10 Thread Olivier Pisano via Digitalmars-d-learn
Hello, I may have not understood what you actually want to do, but aren't std.bitmanip.peek or std.bitmanip.read what you are looking for ? http://dlang.org/phobos/std_bitmanip.html#.peek

Re: What exactly module in D means?

2014-07-05 Thread Olivier Pisano via Digitalmars-d-learn
No, import is different from include. It does not stupidly copy and paste its content but tells the compiler to take the module into account for name resolution. The result may seem similar, but is much more efficient. A D module is also a unit of encapsulation (a private declaration in a module

Re: Equivalent of C++ std::function

2014-06-24 Thread Olivier Pisano via Digitalmars-d-learn
On Wednesday, 25 June 2014 at 03:33:15 UTC, Yuushi wrote: Thanks a ton - I guess I need to do a fair bit more reading about alias. In this case, alias acts as typedef in C++. What is important here is the function pointers/delegates syntax.