stack-overflow

Avoiding stack overflow (with F# infinite sequences of sequences)

时间秒杀一切 提交于 2019-12-17 18:27:09
问题 I have this "learning code" I wrote for the morris seq in f# that suffers from stack overflow that I don't know how to avoid. "morris" returns an infinite sequence of "see and say" sequences (i.e., {{1}, {1,1}, {2,1}, {1,2,1,1}, {1,1,1,2,2,1}, {3,1,2,2,1,1},...}). let printList l = Seq.iter (fun n -> printf "%i" n) l printfn "" let rec morris s = let next str = seq { let cnt = ref 1 // Stack overflow is below when enumerating for cur in [|0|] |> Seq.append str |> Seq.windowed 2 do if cur.[0]

Merge sort from “Programming Scala” causes stack overflow

半腔热情 提交于 2019-12-17 15:37:53
问题 A direct cut and paste of the following algorithm: def msort[T](less: (T, T) => Boolean) (xs: List[T]): List[T] = { def merge(xs: List[T], ys: List[T]): List[T] = (xs, ys) match { case (Nil, _) => ys case (_, Nil) => xs case (x :: xs1, y :: ys1) => if (less(x, y)) x :: merge(xs1, ys) else y :: merge(xs, ys1) } val n = xs.length / 2 if (n == 0) xs else { val (ys, zs) = xs splitAt n merge(msort(less)(ys), msort(less)(zs)) } } causes a StackOverflowError on 5000 long lists. Is there any way to

Merge sort from “Programming Scala” causes stack overflow

烈酒焚心 提交于 2019-12-17 15:37:14
问题 A direct cut and paste of the following algorithm: def msort[T](less: (T, T) => Boolean) (xs: List[T]): List[T] = { def merge(xs: List[T], ys: List[T]): List[T] = (xs, ys) match { case (Nil, _) => ys case (_, Nil) => xs case (x :: xs1, y :: ys1) => if (less(x, y)) x :: merge(xs1, ys) else y :: merge(xs, ys1) } val n = xs.length / 2 if (n == 0) xs else { val (ys, zs) = xs splitAt n merge(msort(less)(ys), msort(less)(zs)) } } causes a StackOverflowError on 5000 long lists. Is there any way to

Stack overflow C++

99封情书 提交于 2019-12-17 14:47:27
问题 This is my code. When I access dtr array in initImg function it gives a stack overflow exception. What might be the reason? #define W 1000 #define H 1000 #define MAX 100000 void initImg(int img[], float dtr[]) { for(int i=0;i<W;i++) for(int j=0;j<H;j++) img[i*W+j]=255; for(int j=0;j<H;j++) { img[j] = 0; img[W*(W-1)+j] = 0; } for(int i=0;i<W;i++) { img[i*W] = 0; img[i*W+H-1] = 0; } for(int i=0;i<W;i++) for(int j=0;j<H;j++) { if(img[i*W+j]==0) dtr[i*W+j] = 0; // <------here else dtr[i*W+j] =

Stack overflow C++

﹥>﹥吖頭↗ 提交于 2019-12-17 14:45:52
问题 This is my code. When I access dtr array in initImg function it gives a stack overflow exception. What might be the reason? #define W 1000 #define H 1000 #define MAX 100000 void initImg(int img[], float dtr[]) { for(int i=0;i<W;i++) for(int j=0;j<H;j++) img[i*W+j]=255; for(int j=0;j<H;j++) { img[j] = 0; img[W*(W-1)+j] = 0; } for(int i=0;i<W;i++) { img[i*W] = 0; img[i*W+H-1] = 0; } for(int i=0;i<W;i++) for(int j=0;j<H;j++) { if(img[i*W+j]==0) dtr[i*W+j] = 0; // <------here else dtr[i*W+j] =

Android: Increase call stack size

独自空忆成欢 提交于 2019-12-17 12:18:15
问题 I have an application with very complex UI, containing many layouts nested one in another. While Creating another layout, I've caught a StackOverflowError Wondering, I've created two test examples: 1) Hello world application with following xml for main Activity <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <FrameLayout android:layout_width="fill_parent"

Android: Increase call stack size

冷暖自知 提交于 2019-12-17 12:18:08
问题 I have an application with very complex UI, containing many layouts nested one in another. While Creating another layout, I've caught a StackOverflowError Wondering, I've created two test examples: 1) Hello world application with following xml for main Activity <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <FrameLayout android:layout_width="fill_parent"

Explanation of R: options(expressions=) to non-computer scientists

狂风中的少年 提交于 2019-12-17 10:57:49
问题 I have written a recursive function of the form foo=function(vars,i=2){ **do something with vars** if(i==length(vars)){ return(**something**) }else{ foo(vars,i+1) } } length(vars) is around 1500. When I execute it, I got the error Error: evaluation nested too deeply: infinite recursion / options(expressions=)? Error during wrapup: evaluation nested too deeply: infinite recursion / options(expressions=)? Fair enough, so I increased options(expressions=10000) Then it works. But when I read the

How can I increase the maximum call stack size in Node.js

二次信任 提交于 2019-12-17 07:20:16
问题 This is different to other questions regarding an error message in Node that reads RangeError: Maximum call stack size exceeded in that I know exactly why I'm getting this error message. It's happening because I'm recursing, recursing quite a lot in fact. Thanks. 回答1: From node --help : node --max-stack-size=val Update: as the comments indicate, even though the help text still lists the --max-stack-size option, in node v0.10.x you need to use --stack-size instead. node --stack-size=val 回答2:

java StackOverflowError when local and instance objects creation

柔情痞子 提交于 2019-12-17 06:57:16
问题 Hi can anybody please explain me why is this code snippet giving me StackOverflowError I really appreciate if you can explain what is happening when instanceObj initializing and calling ObjectTest constructor and java.lang.Object constructor. It seems to me ObjectTest constructor loop over and over.But I don't know exact reason? So any suggestion... public class ObjectTest { public ObjectTest() { } ObjectTest instanceObj = new ObjectTest(); public static void main(String[] args) { ObjectTest