On Sunday, 24 January 2021 at 14:56:25 UTC, Paul Backus wrote:
On Sunday, 24 January 2021 at 11:00:17 UTC, vitamin wrote:
It is Ok when I call deallocate with smaller slice or I need
track exact lengtht?
It depends on the specific allocator, but in general, it is
only guaranteed to work correctly if the slice you pass to
deallocate is exactly the same as the one you got from allocate.
To add to that, if an allocator defines `resolveInternalPointer`
[0][1] you could be able to get the original slice that was
allocated (and then pass that to `deallocate`, but not all
allocators define `resolveInternalPointer` and also even if they
do define it, they're not required to maintain complete
book-keeping as doing so could have bad performance implications
(i.e. calling say `a.resolveInternalPointer(a.allocate(10)[3 ..
6].ptr, result)` can return `Ternary.unknown`.
[0]:
https://dlang.org/phobos/std_experimental_allocator.html#.IAllocator.resolveInternalPointer
[1]:
https://dlang.org/phobos/std_experimental_allocator_building_blocks.html