We studied the influence of the nuclear spin diffusion on the dynamical nuclear polarization of low dimensional nanostructures subject to optical pumping. Our analysis shows that the induced nuclear spin polarization in semiconductor nanostructures will develop both a time and position dependence due to a nonuniform hyperfine interaction as a result of the geometrical confinement provided by the system. In particular, for the case of semiconductor quantum wells, nuclear spin diffusion is responsible for a nonzero nuclear spin polarization in the quantum well barriers. As an example we considered a 57 Å GaAs square quantum well and a 1000 Å AlxGa1-xAs parabolic quantum well both within 500 Å Al0.4Ga0.6As barriers. We found that the average nuclear spin polarization in the quantum well barriers depends on the strength of the geometrical confinement provided by the structure and is characterized by a saturation time of the order of few hundred seconds. Depending on the value of the nuclear spin diffusion constant, the average nuclear spin polarization in the quantum well barriers can get as high as 70% for the square quantum well and 40% for the parabolic quantum well. These results should be relevant for both time resolved Faraday rotation and optical nuclear magnetic resonance experimental techniques.