包内存管理 [英] Package Memory Management

查看:62
本文介绍了包内存管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于尝试使用DLL时遇到很多困难,因此我决定尝试运行时程序包(主要是为了避免内存管理器和类型注册表问题).

Since I have been running in a lot of difficulties when trying to use DLLs, I decided to try out runtime packages (mainly to avoid the memory manager and type registry problems).

在我的应用程序中,我会执行以下操作:

From my application I do something like this:

HandleList := TList <THandle>.Create;
try
  PackageObj.DoSomething (HandleList);
finally
  FreeAndNil (HandleList);
end;

该方法(在运行时包内部)只是向列表中添加了一些内容:

The method (inside the runtime package) just adds something to the list:

procedure TPackageObject.DoSomething (HandleList: TList <THandle>);
begin
  HandleList.Clear;
  HandleList.Add (0);
end;

在程序包中对Clear的调用中或在应用程序中对FreeAndNil的调用中,我确实获得了Invalid Pointer异常.有时也会发生访问冲突.

I do get Invalid Pointer exception either in the call to Clear within the package or in the call to FreeAndNil in the application. Access violations also happen from time to time.

使用FastMM时,有时会报告块头已损坏".

When using FastMM, it sometimes reports "Block Header has been corrupted".

错误总是在分配或释放内存时发生,即向列表中添加内容,从而导致列表动态增长.

The error always happens when memory is allocated or freed, i.e. adding something to the list and therefore causing the list to grow dynamically.

HandleList对象被传递到程序包并返回的方式好吗?关于软件包和内存管理,有什么重要的知识要知道吗?还是错误必须在其他地方?

Is the way the HandleList object is passed to the package and back okay? Is there anything important to know about packages and memory management? Or must the error be somewhere else?

编辑,如果该错误可能在其他地方,我应该如何调试类似的内容?有经验吗?

EDIT In the case that the error is likely to be somewhere else, how am I supposed to debug something like this? Any experiences?

推荐答案

我想您是在不同的程序包(也许也在应用程序可执行文件中)中编译相同的代码.无论您是静态链接运行时软件包(在项目选项中列出它们)还是动态链接(使用LoadPackage),每个单元都必须仅链接到一个模块中,否则会出现重复的代码冲突.检查您的程序包依赖项(requires子句),在主要项目选项中查看运行时程序包的列表,观察有关隐式包含的单元的编译器警告.

I guess you are compiling the same code in different packages, maybe in the application executable, too. Whether you link your runtime packages statically (list them in project options) or dynamically (using LoadPackage), each unit has to be linked into only one module, otherwise you get duplicate code conflicts. Check your package dependencies (requires clauses), list of runtime packages in the main project options, watch compiler warnings about implicitly included units.

这篇关于包内存管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆