digitalmars.D.learn - ndslice and RC containers
- =?UTF-8?B?Tm9yZGzDtnc=?= (7/7) Sep 22 2016 Is ndslice' Slice() prepared for integration with containers with
- ZombineDev (38/45) Sep 22 2016 ndslice (i.e. Slice(size_t N, Range) ) is a generalization of D's
- Ilya Yaroshenko (2/20) Sep 22 2016 Thank you ZombineDev, good answer!
- =?UTF-8?B?Tm9yZGzDtnc=?= (4/11) Sep 22 2016 How will this interact with DIP-1000, specifically, will ref
- Ilya Yaroshenko (2/14) Sep 25 2016 No, `Slice` structure is not data owner.
Is ndslice' Slice() prepared for integration with containers with reference counting semantics? I wonder because according to the docs they internally store a pointer and an offset. What is that pointer supposed to point to except from obviously currently a GC-allocated array? See: https://dlang.org/phobos/std_experimental_ndslice_slice.html#.Slice
Sep 22 2016
On Thursday, 22 September 2016 at 12:38:57 UTC, Nordlöw wrote:Is ndslice' Slice() prepared for integration with containers with reference counting semantics? I wonder because according to the docs they internally store a pointer and an offset. What is that pointer supposed to point to except from obviously currently a GC-allocated array? See: https://dlang.org/phobos/std_experimental_ndslice_slice.html#.Slicendslice (i.e. Slice(size_t N, Range) ) is a generalization of D's built-in slices (i.e. T[]) to N dimensions. Just like them, it doesn't handle memory ownership - it just provides a view over existing data. Usually, there are two use cases: 1) Wrapping an existing array: 1.1) You allocate an array however you want (GC, RC, plain malloc) or just use a slice to an array returned from a third-party library 1.2) Wrap it via sliced [1] 1.3) Use it 1.4) Free it: 1.4.a) Let the GC reclaim it 1.4.b) Let the RC reclaim it 1.4.c) Free it manually. 2) Making a new array 2.1.a) Using the GC via slice [2] 2.1.b) Using std.experimental.allcator via makeSlice [3] 2.2) Use it 2.3) Free it: 2.3.a) Let the GC reclaim it automatically 2.3.b) Manually dispose [4] it from the allocator it was allocated from (look for the allocator.dispose(tuple.array) pattern in the examples of makeSlice). Please note that the support for creating ndslices via custom memory allocators (i.e. makeSlice) was added after dmd-2.071 was branched, so you either have to wait for dmd-2.072, or use a nightly build (which I recommend). [1]: [2]: [3]: [4]:
Sep 22 2016
On Thursday, 22 September 2016 at 13:30:28 UTC, ZombineDev wrote:On Thursday, 22 September 2016 at 12:38:57 UTC, Nordlöw wrote:Thank you ZombineDev, good answer![...]ndslice (i.e. Slice(size_t N, Range) ) is a generalization of D's built-in slices (i.e. T[]) to N dimensions. Just like them, it doesn't handle memory ownership - it just provides a view over existing data. Usually, there are two use cases: 1) Wrapping an existing array: 1.1) You allocate an array however you want (GC, RC, plain malloc) or just use a slice to an array returned from a third-party library 1.2) Wrap it via sliced [1] 1.3) Use it 1.4) Free it: 1.4.a) Let the GC reclaim it 1.4.b) Let the RC reclaim it 1.4.c) Free it manually. [...]
Sep 22 2016
On Thursday, 22 September 2016 at 13:30:28 UTC, ZombineDev wrote:ndslice (i.e. Slice(size_t N, Range) ) is a generalization of D's built-in slices (i.e. T[]) to N dimensions. Just like them, ... Please note that the support for creating ndslices via custom memory allocators (i.e. makeSlice) was added after dmd-2.071 was branched, so you either have to wait for dmd-2.072, or use a nightly build (which I recommend).How will this interact with DIP-1000, specifically, will ref returning members of Slice() be scope-qualified? Thx!
Sep 22 2016
On Thursday, 22 September 2016 at 20:23:57 UTC, Nordlöw wrote:On Thursday, 22 September 2016 at 13:30:28 UTC, ZombineDev wrote:No, `Slice` structure is not data owner.ndslice (i.e. Slice(size_t N, Range) ) is a generalization of D's built-in slices (i.e. T[]) to N dimensions. Just like them, ... Please note that the support for creating ndslices via custom memory allocators (i.e. makeSlice) was added after dmd-2.071 was branched, so you either have to wait for dmd-2.072, or use a nightly build (which I recommend).How will this interact with DIP-1000, specifically, will ref returning members of Slice() be scope-qualified? Thx!
Sep 25 2016