www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Re: File append Limit

reply Joshua Niehus <jm.niehus gmail.com> writes:
--90e6ba6e839e91a4c804a9ca8083
Content-Type: text/plain; charset=ISO-8859-1

 Kagamin

 What if

 foreach(i;0..512) {
  append("/Users/dirList.txt", text("line ",i,'\n'));
 }

That works, but I misrepresented the problem and found that the following may be the issue (this looks more like the code im using): import std.conv, std.stdio; void main() { string[] strArr; foreach(int i; 0 .. 257) { strArr ~= text("Line: " ~ to!string(i)); } foreach(string e; strArr) { writeln(e); } } // OUTPUT for first 87 lines Line: 2 ?O ?O `O O O ?N ?N ... ect.... ... ? ? ` 0 Line: 88 /* rest of output is as expected */ Changing 257 to 256 gives you what you would expect. Josh --90e6ba6e839e91a4c804a9ca8083 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Kagamin<div><br></div><div>&gt;=A0<span class=3D"Apple-style-span" style= =3D"font-family: arial, sans-serif; font-size: 13px; background-color: rgb(= 255, 255, 255); ">What if</span></div><span class=3D"Apple-style-span" styl= e=3D"font-family: arial, sans-serif; font-size: 13px; background-color: rgb= (255, 255, 255); ">&gt;<br> &gt; foreach(i;0..512) {<br>&gt; =A0append(&quot;/Users/dirList.txt&quot;, = text(&quot;line &quot;,i,&#39;\n&#39;));<br>&gt; }</span><div><span class= =3D"Apple-style-span" style=3D"font-family: arial, sans-serif; font-size: 1= 3px; background-color: rgb(255, 255, 255); "><br> </span></div><div><font class=3D"Apple-style-span" face=3D"arial, sans-seri= f">That works, but I=A0misrepresented=A0the problem and found that the foll= owing may be the issue (this looks more like the code im using):</font></di= v><div> <font class=3D"Apple-style-span" face=3D"arial, sans-serif"><br></font></di= v><div><font class=3D"Apple-style-span" face=3D"arial, sans-serif"><div>imp= ort std.conv, std.stdio;</div></font></div><div><font class=3D"Apple-style-= span" face=3D"arial, sans-serif"><br> </font></div><div><font class=3D"Apple-style-span" face=3D"arial, sans-seri= f"><div>void main()</div><div>{</div><div>=A0 =A0 string[] strArr;</div><di= v>=A0 =A0 foreach(int i; 0 .. 257) {</div><div>=A0 =A0 =A0 =A0 strArr ~=3D = text(&quot;Line: &quot; ~ to!string(i));</div> <div>=A0 =A0 }</div><div>=A0 =A0=A0</div><div>=A0 =A0 foreach(string e; str= Arr) {</div><div>=A0 =A0 =A0 =A0 writeln(e);</div><div>=A0 =A0 } =A0</div><= div>}</div><div><br></div><div>// OUTPUT for first 87 lines</div><div><div>= Line: 2</div><div>?O=A0</div> <div>?O=A0</div><div>`O=A0</div><div> O=A0</div><div>=A0O=A0</div><div><br>= </div><div>?N=A0</div><div>?N=A0</div></div><div>...</div><div>ect....</div=
<div>...</div><div><div>? =A0</div><div>? =A0</div><div>` =A0</div><div>0 =

</div><div>Line: 88</div></div><div>=A0/* rest of output is as expected */<= /div><div><br></div><div>Changing 257 to 256 gives you what you would expec= t. =A0</div></font></div><div><font class=3D"Apple-style-span" face=3D"aria= l, sans-serif"><br> </font></div><div><font class=3D"Apple-style-span" face=3D"arial, sans-seri= f">Josh</font></div><div><font class=3D"Apple-style-span" face=3D"arial, sa= ns-serif"><br></font></div> --90e6ba6e839e91a4c804a9ca8083--
Aug 05 2011
parent Kagamin <spam here.lot> writes:
Joshua Niehus Wrote:

 That works, but I misrepresented the problem and found that the following
 may be the issue (this looks more like the code im using):
 
 import std.conv, std.stdio;
 
 void main()
 {
     string[] strArr;
     foreach(int i; 0 .. 257) {
         strArr ~= text("Line: " ~ to!string(i));
     }
 
     foreach(string e; strArr) {
         writeln(e);
     }
 }

Looks like the described problem. 256 strings on 32-bit architecture is an array 2kb long. Move strArr to global scope and see if the code works. If the stack is not scanned by GC, that's bad.
Aug 06 2011