Tôi đã cố gắng chuyển đổi dự án vc7.1 thành vs2010 mà tôi nhận được từ codeproject. (Và đây là liên kết h tt p: //www.codeproject.com/KB/cpp/transactions.aspx? Fid = 11253 & df = 90 & MPP = 50 & tiếng ồn = 3 & sort = Chức & view = Mở rộng & fr = 1 # xx0xxVị trí mới có gọi hàm tạo nếu con trỏ được truyền là null không?
Nhưng sau khi được chuyển đổi và điều chỉnh cấu hình của nó.
tôi thấy nó debug không thành công, nó nói Unhandled ngoại lệ tại 0x0028e7b9 trong DrawIt.exe: 0xC0000005: Vi phạm quyền truy cập ghi vị trí 0x00000000.
Dòng lỗi đi như thế này
data = new(Mm::Allocate(sizeof(DocData), sid)) DocData();
Và chức năng
void* Allocate(size_t size, SPACEID sid)
{
AUDIT
Spaces::iterator s = spaces.find(sid);
if (s == spaces.end())
return NULL;
Space& space = s->second;
if (!space.transacting)
return NULL;
size = max(size, sizeof(Free));
// TODO: assert that "data" is allocated in space
space.AssertData();
// are there any more free chunks?
if (!space.data->sFreeHead) {
space.data->Insert(space.More(size));
}
AUDIT
// find the first chunk at least the size requested
Free* prev = 0;
Free* f = space.data->sFreeHead;
while (f && (f->size < size)) {
prev = f;
f = f->next;
}
AUDIT
// if we found one, disconnect it
if (f) {
space.data->locTree.remove((size_t)f);
if (prev) prev->next = f->next;
else space.data->sFreeHead = f->next;
f->next = 0;
memset(&f->loc, 0, sizeof(f->loc));
} else {
f = space.More(size);
}
// f is disconnected from the free list at this point
AUDIT
// if the free chunk is too(?) big, carve a peice off and return
// the rest to the free list
if (f->size > (2*(size + sizeof(Free)))) {
Free* tmp = space.data->Slice(f, size); // slice size byte off 'f'
space.data->Insert(f); // return the remainder to the free list
f = tmp;
}
AUDIT
CHECK_POINTER(f)
void* p = reinterpret_cast<void*>((char*)f + sizeof(Free::SIZE_TYPE));
CHECK_POINTER(p)
return p;
}
Bất cứ ai có ý tưởng, plz?
Vì tôi không giỏi ở C++, sẽ mất một thời gian trước khi tôi tìm ra cách giải quyết vấn đề này. Chỉ cần tải lên mã nguồn source file, nó sẽ được đánh giá cao nếu ai đó có thể trợ giúp.
Đây là một câu hỏi thực sự tốt có thể được đặt lại trong các thuật ngữ ngắn hơn như sau: * Vị trí mới có gọi hàm khởi tạo nếu con trỏ được truyền không null? * –