To a (projective smooth) algebraic surface $S$ over an algebraically closed field and a divisor $D$ of $S$, we can associate $n= \dim D$ and $g$, the genus of a generic member of $D$. I would like to fix $g$ and vary $S,D$ so as to make $n$ as large as possible. Is $n$ unbounded and, if not, what is the optimal bound? I am mainly interested in the case of positive characteristic but an answer over the complex numbers would be welcome too.
$n$ is unbounded, as it is shown by the following example. EDIT: my example did not work, as pointed out by quim in the comments. The example he suggests however works: take $S$ the blowup of $P^2$ at a point $x$ and $D$ the strict transform of a curve of degree $d$ with a singular point of multiplicity $d1$ at $x$. The general $D$ is smooth and $D$ has dimension $2d$.\ Of course, a similar construction can be used to construct examples with $g>0$. On the other hand, if the Kodaira dimension of $S$ is $\ge 0$ and $D$ is irreducible, then $n=\dimD$ is bounded by $g$ by the following argument. Up to blowing up $S$ we may assume that the general $D$ is smooth.
Let $m>0$ be such that $mK_S\ge 0$. If $n>0$, then $D$ is not in the fixed part of $mK_S$, hence $K_SD\ge 0$. Hence by the adjunction formula $D_D$ is a divisor of $D$ of degree $\le 2g2$ and therefore it satisfies $2\dimD_D\le \deg D$ (this is Clifford's theorem if $D$ is special and it is trivially true otherwise). I, hence $K_S_D$ is effective and $D_D$ is special. Then Clifford's theorem and the adjunction formula give $2(n1)\le D^2\le D^2+K_SD=2g2$. 


The following example shows that $n$ can be unbounded, for any value of $g$, even if $S$ is fixed. Let $C$ be a smooth curve of genus $g$, and let $\mathcal{E}$ be a normalized rank $2$ vector bundle on $E$. Let $\mathfrak{e}$ be the divisor on $C$ such that $\bigwedge^2 \mathcal{E}=\mathcal{O}_C(\mathfrak{e})$, and consider the projective bundle $S:=\mathbb{P}(\mathcal{E}) \stackrel{\pi}{\longrightarrow} C$. Let $C_0$ be a section such that $C_0^2 = \deg \mathfrak{e}$, and let $f$ be the class of a fiber of $\pi$. Assume now that $\mathfrak{b}$ is any divisor on $C$ having the following properties:
Notice that these conditions are satisfied as soon as $\mathfrak{b}$ is a general divisor of sufficiently high degree. By [Hartshorne, Algebraic geometry, Ex. 2.11 p. 385], there exists a section $D$ linearly equivalent to $C_0 + \mathfrak{b} f$, and moreover $D$ is basepoint free. By Bertini's theorem it follows that the general element of $D$ is a smooth curve of genus $g$, and the dimension of $D$ clearly goes to infinity when $\deg \mathfrak{b}$ goes to infinity. 

