On Tue, 16 Aug 2011 15:17:33 -0400, nrgyzer <nrgy...@gmail.com> wrote:

Hi everyone,

I've the following:

private static ubyte[][2][hash_t] classInstances;

this() {

   classInstances[toHash()] = new ubyte[2]; // does not work

}

I want insert every class instance into the hashmap. Every class
instance should be contained in the map after the constructor was
called. When I compile my code, I get "Error: cannot implicitly
convert expression (new ubyte[](2u)) of type ubyte[] to ubyte[][]"
which is logical. But is there any way to insert every instance into
the array and define the array/map for this entry?

It's inadvisable to do this, unless you plan on manually deleting the instances.

The reason is because the hash will maintain a pointer to every class instance, which means the GC will never collect them.

Also, it's hard to know why you selected that type, but changing classInstances to ubyte[][hash_t] should work.

Also, you don't need hash_t, you should be able to do ubyte[][Object] classInstances.

then add like:

classInstances[this] = new ubyte[2];

The call to toHash is implicit.

-Steve

Reply via email to