Steven Schveighoffer:

> A static variable is essentially a scoped global variable.  I think it  
> will work if you make it static.  I've used plenty of static variables  
> that are instances of the struct they are declared in.

It doesn't compile with static variables too, you just need few seconds to try 
it on Codepad:
http://codepad.org/QHm2QNQ7

struct MemoryPool(T) {
    alias T[100_000 / T.sizeof] Chunk;
    static Chunk*[] chunks;
}
struct Foo {
    int x;
    static MemoryPool!(Foo) pool;
}
void main() {}


> But since I think you are implementing the memory  
> pool incorrectly (it makes no sense for each instance of an item to have a  
> pool of itself), you should reexamine what you are trying to do.

Next time I show code I'll replace all variable and type names with foo, baz, 
spam, etc. The memory pool in my dlibs is implemented correctly (I think). The 
code I've shown is just a reduced case, where I have removed the "static" too 
:-)

Bye,
bearophile

Reply via email to