Я пытаюсь реализовать основное управление памятью о линейном индексе, которое считывает данные от сотрудников. CSV и создает индекс в employeeeMex.dat . Затем пользователь может предоставить идентификаторы сотрудников, которые позволили бы коду использовать индекс для поиска записи и распечатать ее. Когда я запускаю код, я продолжаю получать неисправности SEG.==21804== Invalid write of size 1
==21804== at 0x4C2EB43: memcpy@@GLIBC_2.14 (vg_replace_strmem.c:1035)
==21804== by 0x402CE0: Page::read_from_data_file(std::istream&) (in /nfs/stak/users/zaidana/CS540/main.out)
==21804== Address 0x5a31510 is 0 bytes after a block of size 0 alloc'd
==21804== Invalid read of size 1
==21804== at 0x4C2EB40: memcpy@@GLIBC_2.14 (vg_replace_strmem.c:1035)
==21804== Address 0x1fff001000 is not stack'd, malloc'd or (recently) free'd
==21804== Process terminating with default action of signal 11 (SIGSEGV)
==21804== Access not within mapped region at address 0x1FFF001000
==21804== ERROR SUMMARY: 12962 errors from 2 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)
main
#include
#include
#include
#include "linear.h"
using namespace std;
int main(int argc, char* const argv[]) {
LinearHashIndex hashIndex("EmployeeIndex");
hashIndex.createFromFile("Employee.csv");
for (int i = 1; i < argc; i++) {
int empID = stoi(argv);
hashIndex.findAndPrintEmployee(empID);
}
return 0;
}
index
#include
#include
#include
#include
#include
#include
#include
using namespace std;
class Record {
public:
int id, manager_id; // Employee ID and their manager's ID
string bio, name; // Fixed length string to store employee name and biography
Record(vector &fields) {
id = stoi(fields[0]);
name = fields[1];
bio = fields[2];
manager_id = stoi(fields[3]);
}
// Function to get the size of the record
int get_size() {
// sizeof(int) is for name/bio size() in serialize function
return sizeof(id) + sizeof(manager_id) + sizeof(int) + name.size() + sizeof(int) + bio.size();
}
// Function to serialize the record for writing to file
string serialize() const {
ostringstream oss;
oss.write(reinterpret_cast(&id), sizeof(id));
oss.write(reinterpret_cast(&manager_id), sizeof(manager_id));
int name_len = name.size();
int bio_len = bio.size();
oss.write(reinterpret_cast(&name_len), sizeof(name_len));
oss.write(name.c_str(), name.size());
oss.write(reinterpret_cast(&bio_len), sizeof(bio_len));
oss.write(bio.c_str(), bio.size());
return oss.str();
}
void print() const {
cout
Подробнее здесь: https://stackoverflow.com/questions/794 ... -seg-fault
Результаты управления памятью базового индекса хеш -индекса в ошибке SEG ⇐ C++
Программы на C++. Форум разработчиков
1739155768
Anonymous
Я пытаюсь реализовать основное управление памятью о линейном индексе, которое считывает данные от сотрудников. CSV и создает индекс в employeeeMex.dat . Затем пользователь может предоставить идентификаторы сотрудников, которые позволили бы коду использовать индекс для поиска записи и распечатать ее. Когда я запускаю код, я продолжаю получать неисправности SEG.==21804== Invalid write of size 1
==21804== at 0x4C2EB43: memcpy@@GLIBC_2.14 (vg_replace_strmem.c:1035)
==21804== by 0x402CE0: Page::read_from_data_file(std::istream&) (in /nfs/stak/users/zaidana/CS540/main.out)
==21804== Address 0x5a31510 is 0 bytes after a block of size 0 alloc'd
==21804== Invalid read of size 1
==21804== at 0x4C2EB40: memcpy@@GLIBC_2.14 (vg_replace_strmem.c:1035)
==21804== Address 0x1fff001000 is not stack'd, malloc'd or (recently) free'd
==21804== Process terminating with default action of signal 11 (SIGSEGV)
==21804== Access not within mapped region at address 0x1FFF001000
==21804== ERROR SUMMARY: 12962 errors from 2 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)
[b] main [/b]
#include
#include
#include
#include "linear.h"
using namespace std;
int main(int argc, char* const argv[]) {
LinearHashIndex hashIndex("EmployeeIndex");
hashIndex.createFromFile("Employee.csv");
for (int i = 1; i < argc; i++) {
int empID = stoi(argv[i]);
hashIndex.findAndPrintEmployee(empID);
}
return 0;
}
[b] index [/b]
#include
#include
#include
#include
#include
#include
#include
using namespace std;
class Record {
public:
int id, manager_id; // Employee ID and their manager's ID
string bio, name; // Fixed length string to store employee name and biography
Record(vector &fields) {
id = stoi(fields[0]);
name = fields[1];
bio = fields[2];
manager_id = stoi(fields[3]);
}
// Function to get the size of the record
int get_size() {
// sizeof(int) is for name/bio size() in serialize function
return sizeof(id) + sizeof(manager_id) + sizeof(int) + name.size() + sizeof(int) + bio.size();
}
// Function to serialize the record for writing to file
string serialize() const {
ostringstream oss;
oss.write(reinterpret_cast(&id), sizeof(id));
oss.write(reinterpret_cast(&manager_id), sizeof(manager_id));
int name_len = name.size();
int bio_len = bio.size();
oss.write(reinterpret_cast(&name_len), sizeof(name_len));
oss.write(name.c_str(), name.size());
oss.write(reinterpret_cast(&bio_len), sizeof(bio_len));
oss.write(bio.c_str(), bio.size());
return oss.str();
}
void print() const {
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79425999/basic-hash-index-memory-management-results-in-seg-fault[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия