c++ - 分配/声明 __64int (long long int) 数组时出现问题

标签 c++ integer 64-bit variable-declaration

我正在尝试运行此代码:

#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/

相关文章:

algorithm - 使用整数项计算矩阵幂

linux - OpenMPI 多个 MPI_Send 和 MPI_recv 不工作

c# - 字符串中的 double 或整数?

c++ - 我如何在 C++ 中使用 python 库?

c++ - 如何在centos中的c中从IP获取以太网适配器名称

c++ - 如何为 LLVM lld 提供共享库路径?

java - 如何在 Java 中分割一个整数

macos - 如何强制/usr/bin/gcc ->/usr/bin/gcc -m32?

oracle - 适用于Delphi XE的64位Oracle客户端

c++ - 写入文件无法显示所有内容