i'm wondering why you get out of memory i guess its not the complete code, or your array is way to large.
if you program efficiently 16*16 requires 256 bytes (is your array a byte type ?)
if you go for real efficient coding then 16*16 requires only 256 bits
an array of 32 bytes containing each 8 bits could do it, but then you have to work binary
or more easy an array of 16 integers (each 16 bit) and again work binary so zero is of one is on.
the complexity will be in setting the binary values, but thats only a bit of math.
you can do set by OR gate to enable it and other functions to disable a bit.