[erlang-questions] Recursive Heap Allocation

Greg Martin greg@REDACTED
Mon Jul 23 21:50:54 CEST 2012


I'm just learning erlang using Erlang R15B01 (erts-5.9.1) on Windows. I'm
wondering why ipv4_addrs:test(ipv4_addrs:first()) leads to the crash below
and how it can be called so that it doesn't. Thanks.

{1,2,22,127}
{1,2,22,128}
{1,2,22,129}
{1,2,22,130}
{1,2,22,131}
{1,2,22,132}
{1,2,22,133}
{1,2,22,134}

Crash dump was written to: erl_crash.dump
eheap_alloc: Cannot allocate 373662860 bytes of memory (of type "heap").


Abnormal termination


-module(ipv4_addrs).

-export([first/0, next/1, test/1]).

first()->
	{ 1,1,0,0 }.

next( { 255, 255, 255, 255 } ) -> done;	
next( { 9, 255, 255, 255 } ) -> { 11, 0, 0, 0 };
next( { 172, 15, 255, 255 } ) -> { 172, 32, 0, 0 };
next( { 192, 167, 255, 255 } ) -> { 192, 169, 0, 0 };
next( { First, 255, 255, 255 } ) -> { First + 1, 0, 0, 0 };
next( { First, Second, 255, 255 } ) -> { First, Second + 1, 0, 0 };
next( { First, Second, Third, 255 } ) -> { First, Second, Third + 1, 0 };
next( { First, Second, Third, Fourth } ) -> { First, Second, Third, Fourth +
1 }.

test(done) -> done;
test(Addr) ->
	io:format("~p~n", [Addr]),
	Next = next(Addr),
	test(Next).




More information about the erlang-questions mailing list