The problem is that I can zoom in and out, so the number of cells I have to draw will change.
But thinking about it and what Hapax said (I forgot about
sf::PrimitiveType::Lines, thanks!)... My monitor is 1920x1080. When each cell is only one pixel, only 810x590 cells will fit on the screen. If I wanted to draw them all, I'd have to store 2 * 810 + 2 * 590 = 2800 vertices, which isn't that bad! I'll see if drawing that many vertices is okay in every frame (don't want to reallocate arrays when zoom level changes).
But I think if I'll notice slowdowns, I can just have two arrays: for horizontal and for vertical lines. So when I only need to draw 30x40 grid, I can just draw the grid using part of preallocated array of maximum allowed size.