Hi,<div><br></div><div>I managed to reproduce the error and the problem is coming from io:format/2 (I suppose writing is too slow for the loop itself, so, the io buffer gets overflowed). Try this replacing ipv4_addrs:next/1 with this:</div>
<div><br></div><div><div>test(done) -> done;</div><div>test(Addr) -> test(next(Addrs)).</div><div><br></div></div><div>CGS</div><div><br></div><div><br></div><div><br><br><div class="gmail_quote">On Mon, Jul 23, 2012 at 11:50 PM, Greg Martin <span dir="ltr"><<a href="mailto:greg@softsprocket.com" target="_blank">greg@softsprocket.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> I think you're misunderstanding. It's like a 256 based number scheme. 0.255<br>
is followed by 1.0 not 1.255.<br>
<div class="HOEnZb"><div class="h5"><br>
-----Original Message-----<br>
From: Ronny Meeus [mailto:<a href="mailto:ronny.meeus@gmail.com">ronny.meeus@gmail.com</a>]<br>
Sent: Monday, July 23, 2012 2:00 PM<br>
To: Bob Ippolito<br>
Cc: Greg Martin; <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
Subject: Re: [erlang-questions] Recursive Heap Allocation<br>
<br>
Hello<br>
<br>
I think there is an issue in the logic of your code:<br>
<br>
next( { First, Second, Third, 255 } ) -> { First, Second, Third + 1, 0 };<br>
next( { First, Second, Third, Fourth } ) -> { First, Second, Third, Fourth +<br>
1 }.<br>
<br>
If nothing matches, the last clause will do and the last number will be<br>
incremented until 255 is reached.<br>
If I understand you well, I would think that the looping continues with the<br>
last but 1 clause but here is the problem: you pass 0 instead of 255 so<br>
there is no match and you end up in the last clause again.<br>
Result is an endless loop.<br>
<br>
I think the code should be corrected like this:<br>
next( { First, Second, Third, 255 } ) -> { First, Second, Third + 1, 255 };<br>
next( { First, Second, Third, Fourth } ) -> { First, Second, Third, Fourth +<br>
1 }.<br>
<br>
---<br>
Best regards,<br>
Ronny<br>
<br>
On Mon, Jul 23, 2012 at 10:04 PM, Bob Ippolito <<a href="mailto:bob@redivi.com">bob@redivi.com</a>> wrote:<br>
> You're probably generating output too fast, there's no flow control in<br>
> io:format/2. You can generate things to print much faster than they<br>
> get printed, which results in the io server accumulating so many<br>
> messages in its mailbox that you eventually run out of memory and/or<br>
> the machine grinds to a halt due to swapping.<br>
><br>
><br>
> On Mon, Jul 23, 2012 at 12:50 PM, Greg Martin <<a href="mailto:greg@softsprocket.com">greg@softsprocket.com</a>><br>
wrote:<br>
>><br>
>> I'm just learning erlang using Erlang R15B01 (erts-5.9.1) on Windows.<br>
>> I'm wondering why ipv4_addrs:test(ipv4_addrs:first()) leads to the<br>
>> crash below and how it can be called so that it doesn't. Thanks.<br>
>><br>
>> {1,2,22,127}<br>
>> {1,2,22,128}<br>
>> {1,2,22,129}<br>
>> {1,2,22,130}<br>
>> {1,2,22,131}<br>
>> {1,2,22,132}<br>
>> {1,2,22,133}<br>
>> {1,2,22,134}<br>
>><br>
>> Crash dump was written to: erl_crash.dump<br>
>> eheap_alloc: Cannot allocate 373662860 bytes of memory (of type "heap").<br>
>><br>
>><br>
>> Abnormal termination<br>
>><br>
>><br>
>> -module(ipv4_addrs).<br>
>><br>
>> -export([first/0, next/1, test/1]).<br>
>><br>
>> first()-><br>
>>         { 1,1,0,0 }.<br>
>><br>
>> next( { 255, 255, 255, 255 } ) -> done; next( { 9, 255, 255, 255 } )<br>
>> -> { 11, 0, 0, 0 }; next( { 172, 15, 255, 255 } ) -> { 172, 32, 0, 0<br>
>> }; next( { 192, 167, 255, 255 } ) -> { 192, 169, 0, 0 }; next( {<br>
>> First, 255, 255, 255 } ) -> { First + 1, 0, 0, 0 }; next( { First,<br>
>> Second, 255, 255 } ) -> { First, Second + 1, 0, 0 }; next( { First,<br>
>> Second, Third, 255 } ) -> { First, Second, Third + 1, 0 }; next( {<br>
>> First, Second, Third, Fourth } ) -> { First, Second, Third, Fourth<br>
>> +<br>
>> 1 }.<br>
>><br>
>> test(done) -> done;<br>
>> test(Addr) -><br>
>>         io:format("~p~n", [Addr]),<br>
>>         Next = next(Addr),<br>
>>         test(Next).<br>
>><br>
>> _______________________________________________<br>
>> erlang-questions mailing list<br>
>> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
>> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
><br>
><br>
> _______________________________________________<br>
> erlang-questions mailing list<br>
> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br></div>