<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, May 20, 2019 at 1:46 PM Markus Metz <<a href="mailto:markus.metz.giswork@gmail.com">markus.metz.giswork@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br>On Mon, May 20, 2019 at 7:18 PM Vaclav Petras <<a href="mailto:wenzeslaus@gmail.com" target="_blank">wenzeslaus@gmail.com</a>> wrote:<br>><br>> On Mon, May 20, 2019 at 11:57 AM Markus Metz <<a href="mailto:markus.metz.giswork@gmail.com" target="_blank">markus.metz.giswork@gmail.com</a>> wrote:<br>>><br>>> On Mon, May 20, 2019 at 5:39 PM Vaclav Petras <<a href="mailto:wenzeslaus@gmail.com" target="_blank">wenzeslaus@gmail.com</a>> wrote:<br>>> ><br>>> > Hi MarkusM and all,<br>>> ><br>>> > I'm trying to understand if the Segment_open() [1] function fills with zeros or not. I don't think it does since it is calling G_malloc (malloc) or Segment_format_nofill(). However, it is not completely clear to me what is supposed to be doing because documentation still says it calls Segment_format() and I don't understand context of the related commit [2, 3] and the usage of lseek and USE_LSEEK are not clear to me from format.c [4].<br>>><br>>> Segment_open() uses Segment_format_nofill() [1], if it can not use the all-in-memory cache. The documentation has not been updated accordingly (yet).<br>><br>><br><div>> Thank you. Just be to be sure: Now, if you want to ensure that it is zero-filled across platform, you need to do it yourself using Segment_put(), right?</div><div><br></div><div>All modules that use the segment lib use Segment_put() anyway to load data<br></div></div></blockquote><div><br></div><div></div><div>I'm asking about the case when I'm writing a new raster map. Let's say with point binning (r.in.lidar/r.in.pdal) or with a simulation I want the values to be initialized as zeros. I can use Segment_put(), but it seems that what Segment_format() is for. Hence the question about Segment_open_zero_fill() (as something more costly than Segment_open() but cheaper than Segment_open()+Segment_put()).</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div></div><div></div><div>> (Assuming you want to use Segment_open().)</div><div><br></div><div>or Segment_format_nofill() + Segment_init()<br></div></div></blockquote><div><br></div><div>I don't want to use Segment_init(), it is just too low level comparing to your Segment_open() (plus it does not have the all-in-memory mode/code).<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div></div><div><br></div><div>> The exact role of lseek() here is still unclear to me (the hole and \0 bytes).</div><div>man lseek:</div><div>       lseek() allows the file offset to be set beyond the end of the file (but this does not change the size of the file).  If data is later  written<br>       at this point, subsequent reads of the data in the gap (a "hole") return null bytes ('\0') until data is actually written into the gap.<br></div><div><br></div><div>More info: disk space is allocated and file size increases only when actual data are written into the gap<br></div></div></blockquote><div><br></div><div>Thanks. I have seen this, but the segment library is not using the null bytes as zeros, or does it?<br></div><div dir="ltr"> </div><div dir="ltr">> ...<br>>> The advantage of no fill, only lseek, is that it is faster, the disadvantage is that any "no space left on device" error will be encountered only later on, and you always need to check the return code of Segment_put().<br>> ...<br></div><div dir="ltr"><br></div><div>It seems that not all modules are doing this (e.g. r.cost). How big a problem that is? I guess the result is a truncated raster without a warning in case of "no space left on device".</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
</blockquote></div></div>