On Thursday, 3 March 2016 at 19:32:40 UTC, Brian Schott wrote:
On Thursday, 3 March 2016 at 19:01:52 UTC, Erik Smith wrote:
I get the error "allocate is not callable using a non-shared
object" and I'm not sure how to resolve it.
Are you calling `Mallocator.allocate()` or
`Mallocator.instance.allocate()`?
The later works and qualifying the allocator member variable
shared seems to solve the issue. Example:
struct A(T) {
alias Allocator = T;
shared Allocator allocator;
this(string url="") {
allocator = Allocator();
void *p1 = cast(void*)(allocator.allocate(1024));
//void p2[] = allocator.allocate(1024); // ICE
}
}
A!Mallocator a;
However, this seems bad because it assumes that all allocators
are shared. It appears, however that the qualifier can be
attached to the type so maybe there is some meta-programming
tricks that can be used:
alias Allocator = shared T;
I'm not sure if I'm on the right track. Note also the ICE in the
example above.
erik