August 08, 2018 Cannot dispose const array? | ||||
---|---|---|---|---|
| ||||
Hi Dlang community! I've stumbled on an interesting issue with allocators. It seems that we can't get disposed of arrays with const or immutable data. Consider example below: Link: https://run.dlang.io/is/frnQI8 ------------------------------------ import std.stdio; import std.range; import std.algorithm; import std.experimental.allocator; import std.experimental.allocator.mallocator; void main(string[] args) { const(int)[] values = Mallocator.instance.makeArray!(const int)([1, 2, 3, 4]); writeln(values); Mallocator.instance.dispose(values); } ------------------------------------ We'd get following error: /dlang/dmd/linux/bin64/../../src/phobos/std/experimental/allocator/package.d(2398): Error: function std.experimental.allocator.mallocator.Mallocator.deallocate(void[] b) shared is not callable using argument types (const(int)[]) shared /dlang/dmd/linux/bin64/../../src/phobos/std/experimental/allocator/package.d(2398): cannot pass argument array of type const(int)[] to parameter void[] b onlineapp.d(11): Error: template instance `std.experimental.allocator.dispose!(shared(Mallocator), const(int))` error instantiating Is it expected to not be able to dispose out of immutable or const data, or it is a bug that should be fixed? Regards, Alexandru. |
Copyright © 1999-2021 by the D Language Foundation