| Author |
Message |
|
| FredrikSvahn |
Posted: Tue Jun 19, 2007 11:36 pm |
|
|
|
User
Joined: 19 Jun 2007
Posts: 31
|
I made a couple of attempts to use open_port for sum-file on the language shootout (I had no problems getting them accepted, I believe it is still there listed as "Hipe #2"). Unfortunately this approach always seemed to end up using too much heap due to the mailbox of my receiving process filling up faster than I could empty it. Eventually it crashes, probably due to that they run it in a sandbox with only a limited amount of memory? It works ok on my computer at home...
In the slightly more sophisticated version below I tried to close the port when the message queue gets too long. It is *very fast* and actually quite successful in conserving memory too. The bad news is that I end up dropping 16 lines from stdin somewhere along the road, receiving empty messages instead.
Close but no cigar, I guess, unless someone else can spot some obvious beginners error...
Code: -module(sumcol1).
-export([main/1]).
-define(qlen, process_info(self(), message_queue_len)).
main(_)-> add(0, 0, 0).
%Too many messages in queue, close port temporarily
add(In, Sum, {_, M}) when is_port(In), M > 1 ->
add(port_close(In), Sum, ?qlen);
add(In, Sum, {_, M}) when M > 0 ->
receive
{_, {_, {_ ,[]}}} -> add(In, Sum, ?qlen); %%%We shouldn't get these!!!
{_, {_, {_ ,Line}}} -> add(In, Sum + list_to_integer(Line), ?qlen);
{'EXIT',_ ,normal} -> add(In, Sum, ?qlen);
{_, eof} -> io:format("~p~n",[Sum]),
halt()
end;
%Open port
add(In, Sum, _) when not is_port(In) ->
add(open_port({fd, 0, 0},[in, eof, {line, 128}]), Sum, ?qlen);
add(In, Sum, _) -> add(In, Sum, ?qlen). |
|
|
| Back to top |
|
| FredrikSvahn |
Posted: Tue Jun 19, 2007 11:44 pm |
|
|
|
User
Joined: 19 Jun 2007
Posts: 31
|
BTW if some wants to give it a try, I have found that the following command line works
Code: erl -nouser -noshell -noinput -run sumcol1 main w < sumcol_data
while
Code: erl -nouser -noinput -noshell -run sumcol1 main w < sumcol_data
does not work... |
|
|
| Back to top |
|
| ioven |
Posted: Fri Mar 23, 2012 6:18 am |
|
|
|
Joined: 23 Mar 2012
Posts: 8
Location: new york
|
Not many cloaking is finished having detrimental motive. Lots of years before, When i worked with an exceptionally substantial comparison-shopping web page, encouraging this overseas designs connected with it is web-sites crank out far more targeted visitors. On the list of useful factors When i recognized promptly seemed to be so it seemed to be cloaking its very own property websites! Rather than the type of which mankind discovered having merchandise, pics in addition to advertising and marketing content, this cloaked type seemed to be an effective directory inbound links to help the vast majority of different types which is services received merchandise.
When When i added this trouble to help light-weight, the item turned out which the electrical engineer in charge received knowingly performed that. He / she idea it becomes far more useful to yahoo and google to provide an effective directory inbound links to enable them to obtain the information in the exact location. He / she decided not to possibly are aware that cloaking seemed to be up against the policies and may even find the web-sites suspended!
Barcelona Soccer Jersey
Real Madrid Jersey
Cheap Soccer Jerseys
Dr Dre Headphones
Monster Beats
Beats By Dr Dre
Beats Headphones
Dr Dre Headphones Beats Pro
Cheap Beats By Dre
Beats Studio
Beats By Dr Dre
Dre Beats
Monster Beats |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|
|