Forward references and more

bearophile bearophileHUGS at
Tue Oct 13 04:30:11 PDT 2009

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:

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 :-)


More information about the Digitalmars-d-learn mailing list