编辑:只是为了说清楚,这个问题是由我的代码中的拼写错误引起的
pointer = new BYTE(datasize);
Run Code Online (Sandbox Code Playgroud)
本来应该
pointer = new BYTE[datasize];
Run Code Online (Sandbox Code Playgroud)
一切都很好!
结束
嗨!
我在C++项目中的Visual Studio 2005中遇到了奇怪的堆栈溢出问题.
在我的代码中,我有一个
BYTE* pointer;
Run Code Online (Sandbox Code Playgroud)
此指针设置为NULL,然后分配一些内存,然后清除为0x00.像这样:
pointer = NULL;
pointer = new BYTE(dataSize);
memset(pointer,0x00,dataSize);
Run Code Online (Sandbox Code Playgroud)
现在,我已经运行了几次,得到了两个不同的结果.有时候(在程序的后期,当我用delete []删除指针时)它表示堆已损坏,并且在检查调用堆栈似乎_CrtIsValidHeapPointer断言它不是有效指针.但是我检查了这个指针,它似乎对我有效(它有一个内存地址).我错过了什么吗?
在另一种情况下,应用程序冻结了很短的时间,我得到一个堆栈溢出消息.当我检查调用堆栈时,它看起来像这样
something.dll!_heap_alloc_base(unsigned int size=568) Line 105 + 0x28 bytes C
something.dll!_heap_alloc_dbg(unsigned int nSize=532, int nBlockUse=2, const char * szFileName=0x0627fec8, int nLine=608) Line 411 + 0x9 bytes C++
something.dll!_nh_malloc_dbg(unsigned int nSize=532, int nhFlag=0, int nBlockUse=2, const char * szFileName=0x0627fec8, int nLine=608) Line 268 + 0x15 bytes C++
something.dll!_malloc_dbg(unsigned int nSize=532, …Run Code Online (Sandbox Code Playgroud) public int S1x;
public void Execute()
{
Random random = new Random();
S1x = random.Next(14, 146);
if (S1x % 15 != 0)
Fix(S1x);
}
public int Fix(int SX)
{
Random randomG = new Random();
SX = randomG.Next(14, 146);
if (SX % 15 != 0)
Fix(SX); // This is the recursion
return SX;
}
Run Code Online (Sandbox Code Playgroud)
每次运行它都会正常工作,但之后我会尝试再次编译并运行它会给我这个错误:
System.StackOverflowException未处理mscorlib.dll中发生未处理的类型"System.StackOverflowException"异常{无法计算表达式,因为当前线程处于堆栈溢出状态.}
并且,是的,我知道有一种更简单的方法可以做到这一点,但是我的方法是将值设置为等于14到146之间的随机数,同时还要确保它是15的倍数,但仍然可以工作.
我真的很困惑为什么它有时只给我错误信息.
那有什么不对呢?为什么它被标记为无限递归,即使它没有任何无限的东西?
我正在处理具有两个列表框的应用程序.我使用值加载两个列表框,当我继续单击列表框中的项目时,我在调试时收到以下错误.

运行exe会导致应用程序关闭.有时我会收到"访问冲突"消息.
那么我该如何摆脱我的应用程序中的这个错误呢?
编辑
..
主窗体具有刷新所有控件的计时器timer_RefreshCOntrol(intervali 1).
当editBox_one被修改(值)时,调用此函数
Procedure TStringSetting.SetValue (const AValue : String);
Begin
...
If FValueControl <> Nil then
Begin
FValueControl.OnChange := VoidNotifyEvent;
FValueControl.Text := NewValue;
FValueControl.OnChange := EditChange; //<--here the stackoverflow error comes....
end;
end;
Procedure EditChange (Sender: TObject);
Begin
Value := FValueControl.Text;
If Not EditIsValid then FValueControl.Font.Color := clRed
else If Dirty then FValueControl.Font.Color := clBlue
else FValueControl.Font.Color := clWindowText;
If @OldCustomEditChange <> Nil then OldCustomEditChange(Sender);
end;`
the EditChange (Sender: TObject); <--keeps geting called and the …Run Code Online (Sandbox Code Playgroud) 下面的代码创建一个双指针B**的B*.它将使用该指针为另一个指针分配内存,该指针将指向被调用B时创建的实例start():
class A:
class A
{
public:
A()
{
fb = new B*;
*fb = NULL;
}
~A()
{
if(*fb)
delete *fb;
delete fb;
}
B** getfb()
{
return fb;
}
private:
B** fb;
};
Run Code Online (Sandbox Code Playgroud)
class B:
class B
{
public:
B()
{
B** fb = a->getfb();
*fb = this;
}
~B()
{
B** fb = a->getfb();
delete *fb; // <--- stack overflow
*fb = NULL;
}
private:
A* a; …Run Code Online (Sandbox Code Playgroud) 我有一个索引纺织品的递归函数,如果我将它用于大型文本文件,我会得到一个堆栈空间溢出.我想因为我将递归部分放在let部分中我可以避免这个堆栈空间溢出,但我仍然得到它.使用此函数避免堆栈空间溢出的最佳方法是什么?
--lines to Map
parseLinesToWordEntryMap :: Int -> [String] -> M.Map Word [TextLocation] -> (M.Map Word [TextLocation])
parseLinesToWordEntryMap lineNumber [] wordEntryMap = wordEntryMap
parseLinesToWordEntryMap lineNumber (x:xs) wordEntryMap =
let
lineNumber' = lineNumber-1
wordEntryMapRec = parseLinesToWordEntryMap lineNumber' xs wordEntryMap
in
parseLineToWordEntryMap lineNumber x wordEntryMapRec
Run Code Online (Sandbox Code Playgroud) class Program
{
static void Main(string[] args)
{
B foo = new B();
foo.DoWork();
Console.ReadLine();
}
}
public class A
{
public virtual void DoWork() { Console.WriteLine("A"); }
}
public class B : A
{
public override void DoWork() { base.DoWork(); Console.WriteLine("B"); }
}
Run Code Online (Sandbox Code Playgroud)
为什么我没有得到StackOverflow异常?据我所知,foo.DoWork()被调用,然后它调用base.DoWork(),它是虚拟的并且在类B.DoWork()方法中重写,它将重复调用base.DoWork()直到栈溢出.当使用它而不是base(调用self的循环循环)时,很容易实现这种溢出.在这种情况下,什么阻止虚函数覆盖?
我用C语言得到了这段代码:
char *options[100000];
int k[100000];
char *param[100000];
int n;
int i,j;
...
scanf("%d",&n);
for (i=0;i<n;i++)
{
scanf("%s%d",&options[i],&k[i]);
param[i]="On";
}
...
Run Code Online (Sandbox Code Playgroud)
就像程序到达这一点一样:
scanf("%s%d",&options[i],&k[i]);
Run Code Online (Sandbox Code Playgroud)
我得到运行时错误(堆栈溢出).这里的输入应该是这样的:
word1 number1
word2 number2
Run Code Online (Sandbox Code Playgroud)
等等.我不知道为什么会这样.有什么问题?
我尝试编写此类:
public class ModelManager
{
public OmniacareHomeProductionEntities _db;
public CategoriaManager categoriaManager
{
get { return categoriaManager; }
set
{
if (categoriaManager == null)
{
categoriaManager = new CategoriaManagerImpl();
}
}
}
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(ModelManager));
public ModelManager()
{
_db = new OmniacareHomeProductionEntities();
}
}
Run Code Online (Sandbox Code Playgroud)
CategoriaManager是一个接口,CategoriaManagerImpl是一个实现CategoriaManager的类。
我在这种模式下使用ModelManager类:
ModelManager modelManager = new ModelManager();
modelManager.categoriaManager.saveLocalCategory(category, true);
Run Code Online (Sandbox Code Playgroud)
因此,当我尝试运行此代码时,此行有一个StackOverflowError
get
{
return categoriaManager;
}
Run Code Online (Sandbox Code Playgroud)
我的错误在哪里?你能帮助我吗?
我有一张表格
<form:form method="post" commandName="post" htmlEscape="false">
<form:input cssClass="input-field" path="postTitle" placeholder="Post title"/>
<form:textarea id="editor" placeholder="Post" path="postBody"/>
<input type="hidden" id="tagQuery" type="text" placeholder="tags" class="input-field"/><br>
<ul id="mytags"></ul><br><br>
<form:select style="visibility : hidden;" id="tags" path="tags">
</form:select>
<input type="submit" value="Save Post"/>
</form:form>
Run Code Online (Sandbox Code Playgroud)
我使用tagit lib获取标签,因为我已经配置了它
select = document.querySelector("select[name='tags']");
jQuery(document).ready(function() {
jQuery("#mytags").tagit({
singleField: true,
singleFieldNode: $('#tagQuery'),
allowSpaces: true,
minLength: 2,
removeConfirmation: true,
tagSource: function( request, response ) {
//console.log("1");
$.getJSON("/app/getTags", request, function(result) {
response($.map(result, function(item) {
return {
// following property gets displayed in drop down
label: item.tagTitle,
// following …Run Code Online (Sandbox Code Playgroud) stack-overflow ×10
c# ×3
c++ ×2
recursion ×2
.net ×1
c ×1
delphi ×1
delphi-6 ×1
destructor ×1
haskell ×1
interface ×1
java ×1
overriding ×1
random ×1
spring ×1