编译哈希算法时出现内存访问冲突错误
memory access violation error while compiling hashing algorithm
我在将字符串插入内存时出错。0xC0000005访问冲突错误。我试图更改我的数组大小,这会导致分配错误。int 主要部分仅发送字符串单词以插入函数,直到文件结束。
#include<string>
#include<iostream>
#include <fstream>
using namespace std;
const unsigned int MAX = INT16_MAX;
string *words = new string[MAX];
int* instances = new int[MAX];
//int* alloc = new int[MAX];
int ucounts = 0;
static unsigned int FNVHash(string str) {
const unsigned int fnv_prime = 0x811C9DC5;
unsigned int hash = 0;
unsigned int i = 0;
unsigned int len = str.length();
for (i = 0; i < len; i++)
{
hash *= fnv_prime;
hash ^= (str[i]);
}
return hash;
}
void insert(string input) {
//check first, add if not present
if (words[FNVHash(input)] != input) { //<-Compiler shows error here.
words[FNVHash(input)] = input;
instances[FNVHash(input)]=1;
ucounts++;
}
else {
instances[FNVHash(input)]++;
}
}
您没有任何
内容可以将 FNVHash
返回的值限制为 words
使用的索引范围。 要么FNVHash
需要确保哈希在[0..NAX]范围内,要么用户(insert
)需要这样做。
相关文章:
- C++尝试深度复制唯一指针时出现内存访问冲突
- C++中的内存分配(引发异常:读取访问冲突)
- 使用加速进程间创建消息队列 - 内存访问冲突
- C 指针转换会导致内存访问冲突
- 为什么创建进程 API 调用会导致内存访问冲突?
- 使用 std::map 作为本地成员的内存访问冲突
- 编译哈希算法时出现内存访问冲突错误
- 使用内存访问冲突错误
- 堆栈引发内存访问冲突
- 使用 Boost::序列化时内存访问冲突
- 调用std::vector::empty()时内存访问冲突读取位置
- 基于 SAPI 的应用程序在枚举令牌时引发内存访问冲突
- 内存访问冲突
- 使用 VC++ 中的 Try 和 catch 块捕获内存访问冲突
- 对象向量中的内存访问冲突
- "detects_simple_anagram"中的致命错误:地址 0x00000000 处的内存访问冲突:故障地址处没有映射
- 内存访问冲突插入结构在树结构c++
- c++内存访问冲突
- MotorBee dll和c++,内存访问冲突
- 调用FindConnectionPoint时写入内存访问冲突