Alternatively, just drop the multi-dimensional array and access the element at row,col
as buffer[row+col*rows]
where buffer
is an array of size rows*cols
. There are some minimal differences in performance between the two, but pick whichever one seems more comfortable.