XCB:如何免费quot quot&quot由xcb_generate_id分配的XID

发布于 2025-01-30 02:23:42 字数 592 浏览 2 评论 0 原文

(1)在XCB中,我们必须在某些请求之前手动分配XID。例如,

xcb_window_t win = xcb_generate_id(conn);
xcb_create_window(conn, XCB_COPY_FROM_PARENT, win, ...);

我们该怎么做才能释放(或未分配)XID?足以调用 xcb_destroy_window 吗?

(2)在情况下 XCB_CREATE_WINDOW 失败了?例如,

xcb_generic_cookie_t cookie = xcb_create_window_checked(conn, XCB_COPY_FROM_PARENT, win, ...);
if(xcb_request_check(conn, cookie)) ... // xcb_create_window failed.

在上面的示例中, xcb_create_window 失败。因此,XID win 是分配但未使用的。在这种情况下,我们应该为 win 做什么?

(1) In XCB, we must manually allocate XID before some requests. For example,

xcb_window_t win = xcb_generate_id(conn);
xcb_create_window(conn, XCB_COPY_FROM_PARENT, win, ...);

Then, what should we do to free (or unallocate) the XID? Is it enough to invoke xcb_destroy_window?

(2) How about in a case xcb_create_window fails? For example,

xcb_generic_cookie_t cookie = xcb_create_window_checked(conn, XCB_COPY_FROM_PARENT, win, ...);
if(xcb_request_check(conn, cookie)) ... // xcb_create_window failed.

In the example above, xcb_create_window failed. So, the XID win is allocated but not used. What should we do for win in this case?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑,眼淚并存 2025-02-06 02:23:42

足以调用xcb_destroy_window?

是的。可悲的是,我没有任何权威文档可以链接到,所以我可以说“相信我”。

这是问题1的简单答案。答案2 ...嗯,我想它没有一个简单的答案。所以我想您需要“全部真相”。

当X11客户端连接到X11服务器时,将分配一系列使用的XID。这些是服务器响应中的字段 Resource-id-base resource-id bask 此处:https://www.x.org/releases/X11R7.6/doc/xproto/x11protocol.html#server_response

从概念上讲,这两个字段描述了“从0x100到0x200的所有XID都适合您”。

XCB_GENEMERE_ID()现在只需返回该范围的下一个条目,并将其标记为使用。因此,在第一个通话并留在上面的示例之后,“所有XID从0x101到0x200”仍然可用。

这是一个非常简单的数据结构,没有办法返回XID,因为“不再使用”。

那么,使用所有XID后会发生什么?为此,存在XC-MISC扩展:

当它不在XIDS中时,Libxcb将发送XCMISCXIDRANGE,以获取“新的” XIDS和XIDS和XIDS批次然后开始分发它们。

我在引号中写下“新”,因为它实际上是原始XID范围的子范围:X11服务器知道它最初分配了该客户端的哪个范围。它知道正在使用哪些XID。因此,它可以选择一个自由范围并将其退还给客户。

得益于这种机制,LiBXCB不必以任何方式跟踪二手XID。东西只是自动起作用。

Is it enough to invoke xcb_destroy_window?

Yup. Sadly, I don't have any authoritative docs to link to, so I can just say "trust me".

That's the simple answer for question 1. Answer 2... uhm, I guess it does not have a simple answer. So I guess you need "the full truth".

When an X11 client connects to the X11 server, it is assigned a range of XIDs to use. These are the fields resource-id-base and resource-id-mask in the server response here: https://www.x.org/releases/X11R7.6/doc/xproto/x11protocol.html#server_response

Conceptually, these two fields describe something like "all XIDs from 0x100 to 0x200 are for you".

xcb_generate_id() now simply returns the next entry from this range and marks it as used. So, after the first call and staying with the example above, "all XIDs from 0x101 to 0x200" are still available.

This is quite a simple data structure and there is no way to return XIDs as "no longer used".

So, what happens after all XIDs were used? For this, the XC-MISC extension exists: https://www.x.org/releases/X11R7.7/doc/xcmiscproto/xc-misc.html

When it is out of XIDs, libxcb will send a XCMiscGetXIDRange request to get a "new" batch of XIDs and then starts handing out them.

I write "new" in quotes since it is actually a sub-range of the original XID range: The X11 server knows which range it originally assigned this client. It knows which XIDs are in use. Thus, it can pick a free range and return it to the client.

Thanks to this mechanism, libxcb does not have to track used XIDs in any way. Stuff just works automatically.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文