Re: Dynamic Arrays Capacity

2022-06-03 Thread bauss via Digitalmars-d-learn
On Friday, 3 June 2022 at 12:52:30 UTC, Adam D Ruppe wrote: On Friday, 3 June 2022 at 12:49:07 UTC, bauss wrote: I believe it's only true in unicode for utf-32 since all characters do fit in the 4 byte space they have Depends how you define "character". I guess that's true as well, unicode r

Re: Dynamic Arrays Capacity

2022-06-03 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 3 June 2022 at 12:49:07 UTC, bauss wrote: I believe it's only true in unicode for utf-32 since all characters do fit in the 4 byte space they have Depends how you define "character".

Re: Dynamic Arrays Capacity

2022-06-03 Thread bauss via Digitalmars-d-learn
On Thursday, 2 June 2022 at 20:12:30 UTC, Steven Schveighoffer wrote: This statement suggests to me that you have an incorrect perception of a string. A string is a pointer paired with a length of how many characters after that pointer are valid. That's it. `str.ptr` is the pointer to the fir

Re: Dynamic Arrays Capacity

2022-06-02 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 2 June 2022 at 08:14:40 UTC, Mike Parker wrote: You've initialized `str` with a string literal. No memory is allocated for these from the GC. They're stored in the binary, meaning they're loaded into memory from disk by the OS. So `str.ptr` points to a static memory location that's

Re: Dynamic Arrays Capacity

2022-06-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/2/22 1:04 AM, Salih Dincer wrote: Hi, Do I misunderstand? A dynamic array is allocated memory according to the `nextpow2()` algorithm(-1 lapse); strings, on the other hand, don't behave like this... ```d   string str = "0123456789ABCDEF";   char[] chr = str.dup;   assert(str.length

Re: Dynamic Arrays Capacity

2022-06-02 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 2 June 2022 at 08:24:51 UTC, Mike Parker wrote: And so, `&ts[0]` is the same as `&(*ts.ptr + 0)`, or simply `ts.ptr`. That should be the same as `&(*(ts.ptr + 0))`!

Re: Dynamic Arrays Capacity

2022-06-02 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 2 June 2022 at 08:14:40 UTC, Mike Parker wrote: More specifically, it points to the starting address of the allocated block of memory. I posted too soon. Given an instance `ts` of type `T[]`, array accesses essentially are this: ```d ts[0] == *(ts.ptr + 0); ts[1] == *(ts.ptr +

Re: Dynamic Arrays Capacity

2022-06-02 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 2 June 2022 at 05:04:03 UTC, Salih Dincer wrote: Hi, Do I misunderstand? A dynamic array is allocated memory according to the `nextpow2()` algorithm(-1 lapse); strings, on the other hand, don't behave like this... ```d string str = "0123456789ABCDEF"; char[] chr = str.dup;