Pathfinding How to store data for big terrain size

I am trying to implement my own pathfinding solution in unity but cant figures out how to store data. Following is my grid class which stores height, length and neighbour tile of tile.

public class grid { public float XVal; public float ZVal; public int[] NId = new int [8]; } 

With Length and Height of 1, I am creating a grid for terrain size that part of the code works nicely It creates a grid, finds its neighbours. I am saving data in Array

grid[] MyGrid ; 

The problem occurs when terrain size is big ex 1024*1024 so for creating a grid, Considering row and column of terrain total elements of grid becomes row(1024)*column(1024) approx. 1 million. As creating such a big grid while running game is impossible So I created custom inspector and generate grid graph and populate array in the editor. But while loading game as Mygrid array size is 1 million game stucks while loading, To fix that I created subsystem which basically divides Mygrid array in multiple arrays which seems working but is there any other way to efficiently store grid data as dividing array adds complexity in code