【发布时间】:2011-05-01 04:00:36
【问题描述】:
我试图将一个 vc7.1 项目转换为我从 codeproject 获得的 vs2010。(这里是链接 h tt p://www.codeproject.com/KB/cpp/transactions.aspx?fid=11253&df=90&mpp =50&noise=3&sort=位置&view=展开&fr=1#xx0xx
但是经过转换和修改后的配置。
我发现它调试不成功,它说在 DrawIt.exe 中的 0x0028e7b9 处出现未处理异常:0xC0000005:访问冲突写入位置 0x00000000。
错误行是这样的
data = new(Mm::Allocate(sizeof(DocData), sid)) DocData();
还有功能
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;
}
请问有人知道了吗?
由于我不擅长 C++,因此需要一些时间才能弄清楚如何解决这个问题。 刚刚上传了源代码source file,如果有人可以帮忙,将不胜感激。
【问题讨论】:
-
这是一个非常好的问题,可以用更短的术语重申:如果传递的指针为空,placement new 是否调用构造函数?
标签: c++ visual-studio-2010 mfc stl atl