Codeproject上RedoUndo项目迁移到vs2010后显示未初始化的问题。。。

lpfly 2010-10-27 03:15:12
这个基于内存管理的Undo Redo The Easy Way的source code

原文地址http://www.codeproject.com/KB/cpp/transactions.aspx?fid=11253&df=90&mpp=50&noise=3&sort=Position&view=Expanded&fr=1#xx0xx

下载后 运行里面的DrawIt(SDI) 迁移至2010 Build通过但是Debug就出现
Unhandled exception at 0x0116e7b9 in DrawIt.exe: 0xC0000005: Access violation writing location 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;
}



请教何解?
...全文
90 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lpfly 2010-10-27
  • 打赏
  • 举报
回复
upupupupupupupup

65,202

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧