我正在尝试运行此代码:
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include<stdint.h>
#include "BSTTemplate.h"
#include "functions.h"
using namespace std;
int main()
{
const __int64 SIZE = 1000000LL;
__int64 randNum;
binarySearchTree<__int64> bst1;
__int64 numArray[SIZE];
//I have more code after but the problem is occurring at the above code.
return 0;
}
我没有收到任何语法错误,因为它可以编译,但一旦运行就会崩溃。我评论了这些声明之后的所有代码,它以同样的方式崩溃了。我尝试使用 Step Into 来调试它,但它不会超过第一个括号“{”,而是打开一些汇编代码和一个错误,提示堆栈溢出。对我做错了什么有帮助吗?这是我第一次使用大于整数的数据类型。我尝试寻找解决方案,但它们要么没有帮助,要么我不理解它们。我也使用 64 位计算机。
我知道 long int
可以容纳 100 万,但我将使用数十亿的数字,所以我想让所有内容都成为 long long int
(或 __64int
)。
根据 EdMaster 的要求,这里是 BSTTemplate.h 的代码:
template <class type>
class binarySearchTree
{
private:
template<class type>
struct nodeType
{
type info;
nodeType<type> * lLink;
nodeType<type> * rLink;
};
nodeType<type> * root;
public:
binarySearchTree();
int height(nodeType<type> *p);
bool search(const type &searchItem) const;
void insert(const type &newData);
void deleteNode(const type &deleteItem);
void deleteFromTree(nodeType<type> * &p);
int numDups;
};
不确定这将如何导致问题。除了 insert
方法一次分配一个内存之外,所有方法定义都不会分配内存。
最佳答案
"... and an error that says the stack overflowed ..."
const __int64 SIZE = 1000000LL;
// ...
__int64 numArray[SIZE];
可能需要比为您的进程配置的可用堆栈内存更多的堆栈内存(您至少需要 7812 KB:(1000000 * 64/8)/1024 )。尝试使用动态内存分配:
std::vector<__int64> numArray(SIZE);
关于c++ - 分配/声明 __64int (long long int) 数组时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30992624/