Bare code not inside a function just runs. On pattern start. Using @jeff 's init example is good practice though.
From personal experience, performance on 2D arrays can be very slow. You might want to make separate 1D arrays, if possible. Sometimes a frame buffer makes it easier, but sometimes it’s unneeded. For an example of frame buffer like behavior, see Multimap multi-pattern