Re: malloc(s)[0..s] vs cast(T)malloc(s)

2020-10-15 Thread Jack via Digitalmars-d-learn
On Thursday, 15 October 2020 at 01:22:54 UTC, Ali Çehreli wrote: On 10/14/20 1:15 PM, Jack wrote: >> auto x = malloc(s)[0..s]; > https://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation Note that 'x' is passed to emplace() at that link and emplace() requires a slice.

Re: malloc(s)[0..s] vs cast(T)malloc(s)

2020-10-15 Thread Jack via Digitalmars-d-learn
On Wednesday, 14 October 2020 at 21:12:13 UTC, Paul Backus wrote: On Wednesday, 14 October 2020 at 20:15:39 UTC, Jack wrote: [...] The difference is that the first version gives you a `void[]`, and the second version gives you a `T`. Neither version does any bounds checking. Generally,

Re: malloc(s)[0..s] vs cast(T)malloc(s)

2020-10-14 Thread Ali Çehreli via Digitalmars-d-learn
On 10/14/20 1:15 PM, Jack wrote: >> auto x = malloc(s)[0..s]; > https://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation Note that 'x' is passed to emplace() at that link and emplace() requires a slice. That's why the a slice is made from the pointer returned by

Re: malloc(s)[0..s] vs cast(T)malloc(s)

2020-10-14 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 14 October 2020 at 20:15:39 UTC, Jack wrote: What's the difference between: import core.stdc.stdlib : malloc; auto x = malloc(s)[0..s]; and auto x = cast(T)malloc(s); ? I have been using the last but I saw in some code examples, like this[1] the first being used. What's the

malloc(s)[0..s] vs cast(T)malloc(s)

2020-10-14 Thread Jack via Digitalmars-d-learn
What's the difference between: import core.stdc.stdlib : malloc; auto x = malloc(s)[0..s]; and auto x = cast(T)malloc(s); ? I have been using the last but I saw in some code examples, like this[1] the first being used. What's the difference? in the first one bounds checking is performed,