Re: byte and short data types use cases

2023-06-10 Thread Cecil Ward via Digitalmars-d-learn
On Sunday, 11 June 2023 at 00:05:52 UTC, H. S. Teoh wrote: On Sat, Jun 10, 2023 at 09:58:12PM +, Cecil Ward via Digitalmars-d-learn wrote: On Friday, 9 June 2023 at 15:07:54 UTC, [...] On contemporary machines, the CPU is so fast that memory access is a much bigger bottleneck than

Re: byte and short data types use cases

2023-06-10 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jun 10, 2023 at 09:58:12PM +, Cecil Ward via Digitalmars-d-learn wrote: > On Friday, 9 June 2023 at 15:07:54 UTC, Murloc wrote: [...] > > So you can optimize memory usage by using arrays of things smaller > > than `int` if these are enough for your purposes, but what about > > using

Re: byte and short data types use cases

2023-06-10 Thread Cecil Ward via Digitalmars-d-learn
On Saturday, 10 June 2023 at 21:58:12 UTC, Cecil Ward wrote: On Friday, 9 June 2023 at 15:07:54 UTC, Murloc wrote: On Friday, 9 June 2023 at 12:56:20 UTC, Cecil Ward wrote: [...] Is this some kind of property? Where can I read more about this? My last example is comms. Protocol headers

Re: byte and short data types use cases

2023-06-10 Thread Cecil Ward via Digitalmars-d-learn
On Friday, 9 June 2023 at 15:07:54 UTC, Murloc wrote: On Friday, 9 June 2023 at 12:56:20 UTC, Cecil Ward wrote: On Friday, 9 June 2023 at 11:24:38 UTC, Murloc wrote: If you have four ubyte variables in a struct and then an array of them, then you are getting optimal memory usage. Is this

Re: byte and short data types use cases

2023-06-10 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 9 June 2023 at 23:51:07 UTC, Basile B. wrote: Yes, a classsic resource is http://www.catb.org/esr/structure-packing/ So you can optimize memory usage by using arrays of things smaller than `int` if these are enough for your purposes, So, is the sorting correct in a structure like

Re: byte and short data types use cases

2023-06-09 Thread Cecil Ward via Digitalmars-d-learn
On Friday, 9 June 2023 at 15:07:54 UTC, Murloc wrote: On Friday, 9 June 2023 at 12:56:20 UTC, Cecil Ward wrote: On Friday, 9 June 2023 at 11:24:38 UTC, Murloc wrote: If you have four ubyte variables in a struct and then an array of them, then you are getting optimal memory usage. Is this

Re: byte and short data types use cases

2023-06-09 Thread Ali Çehreli via Digitalmars-d-learn
On 6/9/23 08:07, Murloc wrote: > Where can I read more about this? I had written something related: http://ddili.org/ders/d.en/memory.html#ix_memory..offsetof The .offsetof appears at that point. The printObjectLayout() function example there attempts to visualize the layout of the members

Re: byte and short data types use cases

2023-06-09 Thread Basile B. via Digitalmars-d-learn
On Friday, 9 June 2023 at 15:07:54 UTC, Murloc wrote: On Friday, 9 June 2023 at 12:56:20 UTC, Cecil Ward wrote: On Friday, 9 June 2023 at 11:24:38 UTC, Murloc wrote: If you have four ubyte variables in a struct and then an array of them, then you are getting optimal memory usage. Is this

Re: byte and short data types use cases

2023-06-09 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 09, 2023 at 11:24:38AM +, Murloc via Digitalmars-d-learn wrote: [...] > Which raised another question: since objects of types smaller than > `int` are promoted to `int` to use integer arithmetic on them anyway, > is there any point in using anything of integer type less than `int`

Re: byte and short data types use cases

2023-06-09 Thread Murloc via Digitalmars-d-learn
On Friday, 9 June 2023 at 12:56:20 UTC, Cecil Ward wrote: On Friday, 9 June 2023 at 11:24:38 UTC, Murloc wrote: If you have four ubyte variables in a struct and then an array of them, then you are getting optimal memory usage. Is this some kind of property? Where can I read more about this?

Re: byte and short data types use cases

2023-06-09 Thread Cecil Ward via Digitalmars-d-learn
On Friday, 9 June 2023 at 11:24:38 UTC, Murloc wrote: Hi, I was interested why, for example, `byte` and `short` literals do not have their own unique suffixes (like `L` for `long` or `u` for `unsigned int` literals) and found the following explanation: - "I guess short literal is not

byte and short data types use cases

2023-06-09 Thread Murloc via Digitalmars-d-learn
Hi, I was interested why, for example, `byte` and `short` literals do not have their own unique suffixes (like `L` for `long` or `u` for `unsigned int` literals) and found the following explanation: - "I guess short literal is not supported solely due to the fact that anything less than