www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - ndslice and RC containers

reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
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
parent reply ZombineDev <petar.p.kirov gmail.com> writes:
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#.Slice
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. 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
next sibling parent Ilya Yaroshenko <ilyayaroshenko gmail.com> writes:
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:
 [...]
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. [...]
Thank you ZombineDev, good answer!
Sep 22 2016
prev sibling parent reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
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
parent Ilya Yaroshenko <ilyayaroshenko gmail.com> writes:
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:
 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!
No, `Slice` structure is not data owner.
Sep 25 2016