digitalmars.D - std.experimental.allocator and const etc.
- John Colvin (16/16) Jul 15 2018 Currently the API's don't support const(void)[], e.g.
 - Nicholas Wilson (4/20) Jul 16 2018 Probably not, the lifetime of the referenced memory is over.
 - Steven Schveighoffer (4/21) Jul 17 2018 I don't think it's something that was considered. I would expect at
 
Currently the API's don't support const(void)[], e.g.
import std.experimental.allocator : makeArray, theAllocator, 
dispose;
import std.experimental.allocator.mallocator : Mallocator;
void main()
{
     const a = theAllocator.makeArray!ubyte(100);
     theAllocator.dispose(a);
     // can't call RCIAllocator.deallocate(void[] b) with 
const(ubyte)[]
     const(void)[] b = Mallocator.instance.allocate(100);
     Mallocator.instance.deallocate(b);
     // can't call Mallocator.deallocate(void[] b) with 
const(void)[]
}
Is this deliberate? It's pretty annoying.
 Jul 15 2018
On Sunday, 15 July 2018 at 13:06:16 UTC, John Colvin wrote:
 Currently the API's don't support const(void)[], e.g.
 import std.experimental.allocator : makeArray, theAllocator, 
 dispose;
 import std.experimental.allocator.mallocator : Mallocator;
 void main()
 {
     const a = theAllocator.makeArray!ubyte(100);
     theAllocator.dispose(a);
     // can't call RCIAllocator.deallocate(void[] b) with 
 const(ubyte)[]
     const(void)[] b = Mallocator.instance.allocate(100);
     Mallocator.instance.deallocate(b);
     // can't call Mallocator.deallocate(void[] b) with 
 const(void)[]
 }
 Is this deliberate? It's pretty annoying.
Probably not, the lifetime of the referenced memory is over. 
There's a couple of other places where we cast away const and 
shared before destroying and object.
 Jul 16 2018
On 7/15/18 9:06 AM, John Colvin wrote:
 Currently the API's don't support const(void)[], e.g.
 
 import std.experimental.allocator : makeArray, theAllocator, dispose;
 import std.experimental.allocator.mallocator : Mallocator;
 
 void main()
 {
      const a = theAllocator.makeArray!ubyte(100);
      theAllocator.dispose(a);
      // can't call RCIAllocator.deallocate(void[] b) with const(ubyte)[]
 
      const(void)[] b = Mallocator.instance.allocate(100);
      Mallocator.instance.deallocate(b);
      // can't call Mallocator.deallocate(void[] b) with const(void)[]
 }
 
 Is this deliberate? It's pretty annoying.
I don't think it's something that was considered. I would expect at 
least dispose to support it by casting away const.
-Steve
 Jul 17 2018








 
 
 
 Nicholas Wilson <iamthewilsonator hotmail.com> 