Re: Slicing betterC

2018-09-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, September 6, 2018 11:34:18 AM MDT Adam D. Ruppe via Digitalmars-d-learn wrote: > On Thursday, 6 September 2018 at 17:10:49 UTC, Oleksii wrote: > > struct Slice(T) { > > > > size_t capacity; > > size_t size; > > T* memory; > > > > } > > There's no capacity in the slice, that

Re: Slicing betterC

2018-09-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 6 September 2018 at 17:10:49 UTC, Oleksii wrote: struct Slice(T) { size_t capacity; size_t size; T* memory; } There's no capacity in the slice, that is stored as part of the GC block, which it looks up with the help of RTTI, thus the TypeInfo reference. Slices *just*

Re: Slicing betterC

2018-09-06 Thread Oleksii via Digitalmars-d-learn
On Thursday, 6 September 2018 at 17:10:49 UTC, Oleksii wrote: allocatedFoo = foos[0 .. $ + 1];// <= Error: TypeInfo This line meant to be `allocatedFoo = foos[$]`. Sorry about that.

Slicing betterC

2018-09-06 Thread Oleksii via Digitalmars-d-learn
Hi the folks, Could you please share your wisdom with me? I wonder why the following code: ``` import core.stdc.stdlib; Foo[] pool; Foo[] foos; auto buff = (Foo*)malloc(Foo.sizeof * 10); pool = buff[0 .. 10]; foos = pool[0 .. 0 ]; // Now let's allocate a Foo: Foo* allocatedFoo; if