标签: stack-overflow

C#堆栈溢出

我试图找出为什么我得到堆栈溢出异常.我正在为学校作业创建一个简单的纸牌游戏,当我克隆卡片以返回它们时,我得到了堆栈溢出异常.

所以我得到了这个卡类:

public class Card : ICloneable
{
    ....

    #region ICloneable Members

    public object Clone()
    {
        return this.Clone(); // <--- here is the error thrown when the first card is to be cloned
    }

    #endregion
}
Run Code Online (Sandbox Code Playgroud)

我有一个叫做Hand克隆的课程:

internal class Hand
{
        internal List<Card> GetCards()
        {
            return m_Cards.CloneList<Card>(); // m_Cards is a List with card objects
        }
}
Run Code Online (Sandbox Code Playgroud)

最后,我得到了一个扩展方法List:

    public static List<T> CloneList<T>(this List<T> listToClone) where T : ICloneable
    {
        return listToClone.Select(item => (T)item.Clone()).ToList();
    }
Run Code Online (Sandbox Code Playgroud)

错误被卡类(IClonable方法)抛出,

CardLibrary.dll中发生了未处理的"System.StackOverflowException"类型异常

c# stack-overflow icloneable

1
推荐指数
1
解决办法
1380
查看次数

C++堆栈溢出 - visual studio 2008

我声明并初始化了一个具有[100] [1000] [1000]个char元素(100MB)的数组,它没有说第一次堆栈溢出.但是当我运行它一段时间后它会抛出一个堆栈溢出异常!我在项目选项 - >链接器 - >系统中将-Stack Reserve Size-增加到200,000,000,但它没有用!我正在使用2GB Ram.How我如何避免堆栈溢出.

c++ stack-overflow visual-studio-2008

1
推荐指数
1
解决办法
1811
查看次数

StackOverflowException in a .Net Windows Service

In some circumstances my .Net windows service can generate a StackOverflowException. Unfortunately, the behaviour seems to be that the service simply stops dead and doesn't write anything into the event log. I don't even get a message from the service control manager saying the service has failed.

is there any way at all a windows service can detect that such an exception has occurred?

In the documentation for this exception, MSDN says "Note that an application that hosts the common …

.net stack-overflow windows-services

1
推荐指数
1
解决办法
546
查看次数

检测到堆栈溢出时强制gcc编译

我怎么能强制gcc编译一个程序,我在其中声明一个比我的ram大的无符号整数数组 - 没有得到警告警告:"表达式中的整数溢出"?

例如.我有8GB的RAM,我想要声明一个8.5gb的数组.

编辑:

谢谢大家,我发现问题不是数据类型,而是一些预处理器的东西.我花了很长一段时间.:) 我写

#define GIBI 1073741824
#define ARRAYSIZE 2*GIBI
Run Code Online (Sandbox Code Playgroud)

显然编译器不喜欢这样.

c stack-overflow stack gcc gcc-warning

1
推荐指数
2
解决办法
312
查看次数

为什么我在这里得到java.lang.StackOverflowError?

_以下问题的以下程序给出了一系列例外Exception in thread "main" java.lang.StackOverflowError at testing_package.Compute.factorial(Compute.java:105)我不明白为什么会出现此错误.

问题:N个男孩和M个女孩正在从剧院学习表演技巧.为了表演,他们需要组成一组P演员,其中包含不少于4个男孩和不少于1个女孩.剧院要求你写一个程序,告诉他们组的形成方式.注意:组成应该是唯一的,而不是组成的顺序.

import java.io.*;

class Compute {

private static int NFact;
private static int N_Minus_R_Fact;
private static int RFact;
private static int fact=0;

public static int readTheStrengthOfGroup() {
    int strengthOfGroup=0;
    try {
        System.out.println("Enter the strength of group : ");
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String read = reader.readLine();
        strengthOfGroup = Integer.parseInt(read);
    } catch(Exception exc) {
        System.out.println(exc);
      }
      return strengthOfGroup;
}

public static int readTheNumberOfBoys() {
   int boysToParticipate=0;
   try {
    System.out.println("Enter …
Run Code Online (Sandbox Code Playgroud)

java stack-overflow recursion exception factorial

1
推荐指数
1
解决办法
904
查看次数

不知道为什么我得到堆栈溢出

我不明白为什么当我进入main函数时我立即得到堆栈溢出.我应该从文本文件中读取并进行一些处理.有人可以向我解释原因,并建议如何解决它?

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <iomanip>

using namespace std;
const int MAX=100;
enum countrytype{S,F};

struct dob
{
int day;
int month;
int year;
};

struct Local
{
char country[MAX];
char gender[MAX];
char name[MAX];
dob birthday;
int noofmod;
char mod[MAX][MAX];
int mark[MAX];

};

struct Foreign
{
char country[MAX];
char gender[MAX];
char name[MAX];
dob birthday;
int noofmod;
char mod[MAX][MAX];
int mark[MAX];

};

union Student
{
Local localstudent;
Foreign foreignstudent;

};

struct UOWstudent
{
countrytype ct;
Student st; …
Run Code Online (Sandbox Code Playgroud)

c++ memory stack-overflow

1
推荐指数
1
解决办法
158
查看次数

Textwatcher给出Stackoverflow错误

我正在制作一个使用TextWatcher的长度转换器.缩短的代码是

 v1.addTextChangedListener(new TextWatcher() {

         @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                val1=Double.parseDouble(v1.getText().toString()); 
                val2=InchToCm(val1); 
                val3=InchToMl(val1);
                val4=InchToKm(val1);
                val5=InchToM(val1);
                val6=InchToY(val1);
                val7=InchToFt(val1);
                val8=InchToLg(val1);
                val9=InchToLgn(val1);
                val11=InchTomm(val1);
                val12=InchToNm(val1);


                v2. setText(Double.toString(val2)); 
                v3. setText(Double.toString(val3)); 
                v4. setText(Double.toString(val4)); 
                v5. setText(Double.toString(val5)); 
                v6. setText(Double.toString(val6)); 
                v7. setText(Double.toString(val7)); 
                v8. setText(Double.toString(val8));
                v9. setText(Double.toString(val9)); 
                v11. setText(Double.toString(val11)); 
                v12. setText(Double.toString(val12));

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
     v2.addTextChangedListener(new TextWatcher() {

         @Override
            public void beforeTextChanged(CharSequence s, int start, int …
Run Code Online (Sandbox Code Playgroud)

eclipse stack-overflow android android-edittext

1
推荐指数
1
解决办法
3447
查看次数

ANTLR4在更长的文件上抛出java.lang.StackOverflowError

我正在研究一种语法,该语法分析潜在的大型降价式文本。文本的“代码”部分用于构建要评估的AST,而其余文本则被忽略。我的实现方式是读取文本,直到找到“`”符号(重音符号),然后再推“代码”模式,该模式负责解析允许的表达式。下一个重音将弹出此模式并继续循环。

问题是读取较大的文本块时出现堆栈溢出错误:

Exception in thread "main" java.lang.StackOverflowError
    at org.antlr.v4.runtime.CommonToken.<init>(CommonToken.java:113)
    at org.antlr.v4.runtime.CommonTokenFactory.create(CommonTokenFactory.java:94)
    at org.antlr.v4.runtime.CommonTokenFactory.create(CommonTokenFactory.java:40)
    at org.antlr.v4.runtime.Lexer.emit(Lexer.java:269)
    at org.antlr.v4.runtime.Lexer.nextToken(Lexer.java:180)
    at org.antlr.v4.runtime.BufferedTokenStream.fetch(BufferedTokenStream.java:187)
    at org.antlr.v4.runtime.BufferedTokenStream.sync(BufferedTokenStream.java:170)
    at org.antlr.v4.runtime.BufferedTokenStream.consume(BufferedTokenStream.java:154)
    at org.antlr.v4.runtime.Parser.consume(Parser.java:588)
    at org.antlr.v4.runtime.Parser.match(Parser.java:220)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:160)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.start_line(TestGrammarParser.java:113)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:168)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at decimill.parser.TestGrammarParser.line(TestGrammarParser.java:161)
    at …
Run Code Online (Sandbox Code Playgroud)

java stack-overflow parsing antlr4

1
推荐指数
1
解决办法
640
查看次数

堆栈溢出异常中c ++和c#之间的区别

当我在C#中编写一些代码时,我有一个递归方法,在几千次调用后导致堆栈溢出异常.
所以过了一会儿,我在C++中编写了相同的代码,它没有例外地工作得很好(即使递归调用的实际数量比C#停止的地方大10倍).
C#和C++在处理这个问题上有什么区别?有没有什么方法可以允许在C#中进行更多的递归调用而不抛出异常?

c# c++ stack-overflow recursion

1
推荐指数
1
解决办法
136
查看次数

Kotlin递归堆栈溢出

我在Kotlin写了这个递归函数:

fun recursive(target: String, population: Population, debugFun: (String) -> Unit) : Population {
    if (population.solution(target).toString() == target) {
        return population
    }
    debugFun.invoke(population.solution(target).toString())
    return recursive(target, population.evolve(target), debugFun)
}
Run Code Online (Sandbox Code Playgroud)

它将运行不确定的次数(因为我使用随机性来收敛进化算法中的解决方案).我经常得到堆栈溢出.Kotlin/JVM语言的最大堆栈深度是多少?我应该非递归地编写函数吗?

stack-overflow recursion tail-recursion kotlin

1
推荐指数
1
解决办法
220
查看次数