各位大侠:
小弟程序如下:
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <math.h> #pragma comment(linker,"/STACK:10240,2048")void diufan(int i)
{
int sp_; _asm {
// mov esp, 0x400;
    mov sp_, esp; //// mov sp_, esp;
  };
  i = i - 1;
  if(i == 0) return ;
  printf("%d %d\n\r",sp_,i);
  diufan(i);}
void main()
{
diufan(1000000);
}但是似乎和系统默认的OVERFLOW情况相同,即益出点相同,请各位帮忙!
谢谢

解决方案 »

  1.   

    #pragma comment(linker,"/STACK:10240,2048")
    在这里好象无法用/STACK这个LINKER option#pragma comment中支持的linker options只有下面几种:
    Only the following linker options are available to be passed to the linker identifier: /DEFAULTLIB 
    /EXPORT 
    /INCLUDE 
    /MERGE 
    /SECTION 所以在工程配置中设置一下试试
      

  2.   

    终于等来了高手,我在project->settings->link->output里面修改
    RESERVE 2048
    COMMIT 1024
    还是不行,难道输入的格式有限制?
      

  3.   


    RESERVE 10240
    COMMIT 2048
    但结果还是不变,不知道为什么
      

  4.   

    也可能是你程序的问题, 为什么要用汇编修改ESP, 要是把CALL STACK破坏了呢?
      

  5.   

    那句话没有修改ESP啊,只是读ESP的值以供输出,
      

  6.   

    i的初始值是1000000,当i输出为997304时益出,每次都是这么多,可否通过你的QQ聊?
      

  7.   

    // test.cpp : Defines the entry point for the console application.
    //#include "stdafx.h"
    #include "stdio.h"
    #include "wchar.h"
    #include "tchar.h"
    #include "windows.h"void recu(int i);int _tmain(int argc, _TCHAR* argv[])
    {
    recu(1000000); return 0;
    }void recu(int i)
    {
    unsigned long _esp;
    _asm mov _esp, esp;
    _tprintf( TEXT("ESP = %08x i = %d\n"), _esp, i); i = i - 1;
    if( i == 0 )
    return;
    else
    recu(i);
    }我的不会, 加了个else就好了
      

  8.   

    抱歉, 弄错了, 我的stack设为10484857600后, 溢出在540172, 比997304小, 说明起作用了./STACK:104857600:1048576
      

  9.   

    和else没有关系吧?我的QQ247524240
      

  10.   

    你是说从程序中? 我不知道, 可能保存在EXE的文件头中吧
      

  11.   

    HEHE, 把星星都惊动了, void recu(int i)一次调用, ESP至少向下移动16字节, 16字节*1000000 = ??晕了. 我把reserved设置为1048576000, 没溢出^-^!
      

  12.   

    不对, 是1000MB, 即差点不到1G, 因为是虚存, 只是保留地址空间, 没有分配实际存储体吧如果再大比如超过2G, 可能就不行了, 我没试, 你试试
      

  13.   

    MSDN的说法
    Generally, the reserve size is the default reserve size specified in the executable header. However, if the initially committed size specified by dwStackSize is larger than the default reserve size, the reserve size is this new commit size rounded up to the nearest multiple of 1 MB. 也就是说堆栈的内存大小是有极限的,你设置大于极限的大小是没有用的。
      

  14.   

    这句话的意思应该是如果commit size大于reserve size, 那么reserve size就变成commit size?
      

  15.   

    1048576000字节 / 1024 = 1024000 K字节
    1024000K / 1024 = 1000MB看你楼上星星的话.
      

  16.   

    默认的线程堆栈是1024KB大小,1000000次的递归肯定会溢出,这么深的递归调用,建议还是改成别的算法比较合适。想要看堆栈大小,用WINDOWS核心编程源码里的VMMAP这一个例子看。不过不要在出现溢出后看,要在之前,出现溢出时带G标志的地址没有了,所以VMMAP无法判断哪块空间是线程堆栈