我正在尝试使用VSTO在Excel中构建一个模拟工具,并创建一个Visual Studio 2010 Office工作簿项目.本工作簿中的一个工作表将包含大约五十万条记录.理想情况下,我想阅读所有在模拟中使用它们的记录,然后输出一些统计信息.到目前为止,OutOfMemory当我试图获得整个范围然后一次性完成细胞时,我有例外.有没有人对我如何阅读所有数据或建议有其他想法?
这是我的代码:
Excel.Range range = Globals.shData.Range["A2:AX500000"];
Array values = (Array)range.Cells.Value;
以下内容发生在linux 2.6.32-220.7.1.el6.x86_64和g++ 4.4.6.
以下代码:
#include <iostream>
#include <cstdlib>
int PROB_SIZE = 10000000;
using namespace std;
int main(int argc, char *argv[]) {
unsigned int numbers[PROB_SIZE];
cout << "Generating " << PROB_SIZE << " random numbers... " << flush;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
产生以下SIGSEGV :( gdb)运行启动程序:/ home/cpd20202/sorting/error
Program received signal SIGSEGV, Segmentation fault.
0x000000000040093b in main (argc=1, argv=0x7fffffffe4f8) at error.cpp:13
13 cout << "Generating " << PROB_SIZE << " random numbers... " << flush;
Missing separate debuginfos, use: debuginfo-install …Run Code Online (Sandbox Code Playgroud) 当我编写以下程序时,它可以正常工作,即在 main() 方法之外声明了 bitset 数组。
正确工作
#include <iostream>
#include <bitset>
using namespace std;
bitset<5000> set[5000];
int main(){
cout<<"program runs fine"<<endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是当我在 main 方法中创建它时,我得到了堆栈溢出异常。谁能详细解释一下这里发生了什么?通常我会在递归方法中看到堆栈溢出异常。那么谁在这里使用堆栈?
#include <iostream>
#include <bitset>
using namespace std;
int main(){
bitset<5000> set[5000];
cout<<"program runs fine"<<endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
不起作用并抛出堆栈溢出异常

我的问题,现在简化为 - 希望 - 最小的例子,是以下代码段错误的原因.
如果您找到后者,它当然可以被视为提议问题的副本.问题是,我在初始搜索中找不到问题,所以可能有很多新手,不知道错误的原因.我建议将此作为我可以找到的副本:
但问题描述很长,所以我相信我的最小化和更短的代码可能更好地说明问题.在任何情况下,它都是重复的.我建议主持人将其设置为副本,并设置从第二个可能副本到第一个副本的链接.
#include <stdio.h>
/* Parameters */
#define N 3072
#define LDA N
/* Main program */
int main() {
printf( "-----------------------------------------------> Entry main.\n" );
/* Local arrays */
double a[LDA*N];
printf( "-----------------------------------------------> End main.\n" );
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当发生段错误时不会发生
#define N 3072
Run Code Online (Sandbox Code Playgroud)
被替换为
#define N 5
Run Code Online (Sandbox Code Playgroud)
线路时也不会发生段错误
double a[LDA*N];
Run Code Online (Sandbox Code Playgroud)
省略.
我特别感到困惑的是,在没有达到的情况下发生了段错误
printf( "-----------------------------------------------> Entry main.\n" );
Run Code Online (Sandbox Code Playgroud)
我直接放在主要的开头.
为了完整性,我运行如下代码:
ludi@ludi-M17xR4:~/Desktop/tests$ g++ -o minicombo.x minicombo.cc && ./minicombo.x
Run Code Online (Sandbox Code Playgroud) #include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
float x[1000][1000];
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到"s.exe中0x01341637的第一次机会异常:0xC00000FD:堆栈溢出." 为什么?
可能重复:
大型阵列上的分段错误
运行程序时发生分段错误.
#include<iostream>
using namespace std;
int main(){
int x[2000][2000];
int y;
cin >> y;
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行它们时,以下两个程序都可以.
#include<iostream>
using namespace std;
int x[2000][2000];
int main(){
int y;
cin >> y;
}
Run Code Online (Sandbox Code Playgroud)
和
#include<iostream>
using namespace std;
int main(){
int x[2000][2000];
int y;
}
Run Code Online (Sandbox Code Playgroud)
我很困惑.谁能告诉我为什么?
你们在这段代码上给了我很大帮助。首先我要说的是,我不太了解 C,但我正在努力做到这一点。
这是程序应该做的事情:
我只是想测试这个 shell 排序程序与标准库中内置的快速排序。
我尝试过使用和不使用指针。注释掉的部分在完成后应该可以工作。它只会让事情变得更加混乱,哈哈
请帮帮我,到目前为止你们都很棒......
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void shellSort(int *A, int n);
void checkSort(int *A, int n);
int main(){
/*Initialize Random Array*/
int unsorted_list[10000000];
int *ptr = &unsorted_list[0];
int random_number;
int i;
srand ( time(NULL) );
for(i=0; i<10000000; i++){
random_number = rand();
unsorted_list[i] = random_number % 10000000;
}
//Do C Shell Sort
double shell_results[10][2];
double clock_diff;
int j=10000000;
clock_t t0, t1;
int …Run Code Online (Sandbox Code Playgroud) 我有以下程序:
#include <stdio.h>
#include <sys/resource.h>
int main()
{
// Anything over ~8MB fails
short int big[4000000];
printf("%lu\n", sizeof(big));
}
Run Code Online (Sandbox Code Playgroud)
ulimit表明我的程序有无限的可用内存。但是,如果我尝试分配更多的内存,则会出现错误:
short int big[6000000];
$ gcc main.c -o main.out && ./main.out
Segmentation fault: 11
Run Code Online (Sandbox Code Playgroud)
我需要在C程序中进行任何更改,以便分配例如1GB的阵列吗?
我正在开发一个代码,其中需要声明大小为150000的double的数组,并且当一个数组声明代码正在成功运行时.如果我们声明两个数组然后执行它终止抛出异常.
Code is :
double a[150000];
double b[150000];
Run Code Online (Sandbox Code Playgroud)
如果我们声明一个只有它然后它完美地执行.如果声明a和b然后它终止.谁能建议如何解决这个问题?
当我在下面的代码中调用我的SegTree结构的构造函数时,我不断得到一个非零的退出代码.当我注释掉初始化结构的行时,程序运行没有问题.有人可以解释为什么会发生这种情况以及如何修复我的代码吗?
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <vector>
#include <string.h>
using namespace std;
struct SegTree{
int N;
long long tree [1<<20], arr [1<<20];
SegTree(int x){ N = x; }
};
int main(){
SegTree st(len);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
请帮助,并提前感谢!
编辑:我的问题不是数组的大小,正如我在评论中提到的那样.我可以创建数组并在将它们放在结构外部时运行代码.