Tcl扩展:扩展ClientData的生命周期 [英] Tcl extensions: Life Cycle of extensions' ClientData

查看:115
本文介绍了Tcl扩展:扩展ClientData的生命周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非平凡的本机扩展将需要动态分配的每个解释器数据
结构。

Non-trivial native extensions will require per-interpreter data structures that are dynamically allocated.

我当前正在使用Tcl_SetAssocData,且密钥对应于
是扩展名的名称和适当的删除例程,
是为了防止该内存泄漏。

I am currently using Tcl_SetAssocData, with a key corresponding to the extension's name and an appropriate deletion routine, to prevent this memory from leaking away.

但是,Tcl_PkgProvideEx也允许记录这样的
信息。可以通过
Tcl_PkgRequireEx检索此信息。将扩展程序的数据结构
与它的程序包关联起来似乎比在抓包
AssocData中更自然。但是Pkg * Ex例程不提供
自动调用的删除例程。因此,我认为我需要
来保留AssocData方法。

However, Tcl_PkgProvideEx also allows one to record such information. This information can be retrieved by Tcl_PkgRequireEx. Associating the extension's data structures with its package seems more natural than in the "grab-bag" AssocData; yet the Pkg*Ex routines do not provide an automatically invoked deletion routine. So I think I need to stay with the AssocData approach.

Pkg * Ex例程针对哪些情况设计?

For which situations were the Pkg*Ex routines designed for?

此外,Tcl库允许安装
ExitHandlers和ThreadExitHandlers。

Additionally, the Tcl Library allows one to install ExitHandlers and ThreadExitHandlers. Paraphasing the manual, this is for flushing buffers to disk etc.

还有其他情况需要使用ExitHandlers吗?

Are there any other situations requiring use of ExitHandlers?

当Tcl调用退出时,会调用Tcl_PackageUnloadProcs吗?

When Tcl calls exit, are Tcl_PackageUnloadProcs called?

推荐答案

整个扩展ClientData用于扩展想要发布自己的存根表(即代表确切的ABI的功能的有组织的列表), other 扩展可以对其进行构建。这是一件非常罕见的事情。如果您不希望使用NULL,请保留为NULL(如果愿意,请直接与Tcl核心开发人员的邮件列表联系;我们在这一领域有很多经验)。由于它是ABI结构,因此强烈应该是纯静态数据,因此不需要删除。动态数据应通过不同的机制发送(例如,通过Tcl解释器或通过ABI调用函数)。

The whole-extension ClientData is intended for extensions that want to publish their own stub table (i.e., an organized list of functions that represent an exact ABI) that other extensions can build against. This is a very rare thing to want to do; leave at NULL if you don't want it (and contact the Tcl core developers' mailing list directly if you do; we've got quite a bit of experience in this area). Since it is for an ABI structure, it is strongly expected to be purely static data and so doesn't need deletion. Dynamic data should be sent through a different mechanism (e.g., via the Tcl interpreter or through calling functions via the ABI).

退出处理程序(可以在多个级别注册) )是您必须在适当的时候删除某些资源时使用的东西。典型的兴趣点是何时删除解释器( Tcl_Interp 结构),何时删除线程以及何时整个进程消失。需要特别删除哪些资源?嗯,通常很明显:文件句柄,数据库句柄之类的东西。一般而言,由于细节非常重要,所以很难回答:问一个更具体的问题以获取量身定制的建议。

Exit handlers (which can be registered at multiple levels) are things that you use when you have to delete some resource at an appropriate time. The typical points of interest are when an interpreter (a Tcl_Interp structure) is being deleted, when a thread is being deleted, and when the whole process is going away. What resources need to be specially deleted? Well, it's usually obvious: file handles, database handles, that sort of thing. It's awkward to answer in general as the details matter very much: ask a more specific question to get tailored advice.

但是,仅在响应于卸载命令。与程序包加载回调一样,它们使用特殊功能符号注册,并且如果不存在,则 unload 命令将拒绝卸载程序包。 大多数软件包不使用它们。用例是存在寿命很长的进程,需要为其添加额外的可升级功能。

However, package unload callbacks are only called in response to the unload command. Like package load callbacks, they use "special function symbol" registration, and if they are absent then the unload command will refuse to unload the package. Most packages do not use them. The use case is where there are very long-lived processes that need to have extra upgradeable functionality added to them.

这篇关于Tcl扩展:扩展ClientData的生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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