Dear Barry, <div> Thanks for your reply. </div><div><br></div><div>best,</div><div>Alan</div><div> <br><br><div class="gmail_quote">On Thu, Aug 18, 2011 at 5:49 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div></div><div class="h5"><br>
On Aug 18, 2011, at 5:02 PM, Alan Wei wrote:<br>
<br>
> Dear all,<br>
> I hope you're having a nice day.<br>
> I'm trying to get the x, y-value of a coordinate created by DMDACreate2d. Lines I wrote down are:<br>
><br>
> DMDAGetCoordinateDA(da, &cda);<br>
> DMDAGetGhostedCoordinates(da, &gc);<br>
> DMDAVecGetArray(cda, gc, &coors);<br>
><br>
> for (i = xs; i < xs+xm; i++) {<br>
> for (j = ys; j < ys+ym; j++) {<br>
> printf("%f %f\n", coors[j][i].x, coors[j][i].y);<br>
> }<br>
> }<br>
><br>
> DMDAVecRestoreArray(cda, gc, &coors);<br>
><br>
> I wonder why I need to use "DMDAVecRestoreArray(cda, gc, &coors);" I used it because the manual said I need. Actually, I tried to comment it out and there is no difference.<br>
><br>
> Thanks,<br>
> Alan<br>
<br>
</div></div> The practical reason is you might get memory bleeding if you don't. The philosphical reason is that a call DMDAVecGetArray() or VecGetArray() or others is a request to access the internal data structure of an object, the object then gives you permission to access that data. the RestoreArray() is a statement by you that after this call you will NOT access that data directly (without another GetArray call). Imagine if you did<br>
<font color="#888888"><br>
Barry<br>
<br>
<br>
<br>
<br>
</font></blockquote></div><br></div>