使用glib而不调用g_main_loop_run?

时间:2022-06-01 23:56:51

Is it correct to use (parts of) GLib without calling g_main_loop_run? If so, how to identity which parts of GLib I can use like this?

使用GLib而不调用g_main_loop_run是否正确?如果是这样,如何识别出我可以使用的油嘴滑舌的哪些部分?

I'm mostly interested in (as referred to by https://developer.gnome.org/glib/2.34/index.html):

我最感兴趣的(https://developer.gnome.org/glib/2.34/index.html):

  1. GLib Data Types;
  2. 口齿伶俐的数据类型;
  3. GLib Utilities.
  4. 口齿伶俐的实用工具。

Common sense tells me that there should be nothing there to require GMainLoop (except Timers, may be?), but I'm a complete GLib newbie, and somehow didn't find any explicit statement in the docs when GMainLoop is required and when not.

常识告诉我,应该没有什么需要GMainLoop(除了计时器,可能是?),但是我是一个完整的GLib新手,在需要GMainLoop的时候,在文档中没有找到任何明确的语句。

From "GLib Core Application Support" section I'd like to use Message Logging, but not sure about it interaction with main loop.

在“GLib核心应用程序支持”一节中,我想使用消息日志记录,但不确定它是否与主循环交互。

For those wondering about why, I use FUSE/osxfuse, which already has its main loop, and I'm not sure how easy it is to deconstruct it and integrate into GMainLoop.

对于那些想知道原因的人,我使用FUSE/osxfuse,它已经有它的主循环,我不确定解构它并集成到GMainLoop有多容易。

Also, I welcome alternative C library suggestions. Looking through GLib docs I rather like it, but I feel uneasy about it trying to be a framework, rather than a set of libraries.

同时,我也欢迎C库的建议。我很喜欢它,但我不喜欢它作为一个框架,而不是一组库。

1 个解决方案

#1


2  

Very little of the GLib code requires the main loop, timers for example are implemented using the system's normal timestamp.

很少的GLib代码需要主循环,例如,计时器是使用系统的正常时间戳实现的。

The code that does require the main loop will reference it, such as the IO Channels. Even then you can see that it's possible to use the IO Channels with or without the main loop, it's your choice.

需要主循环的代码将引用它,比如IO通道。即使这样,您也可以看到,可以使用带有主循环的IO通道,也可以不带主循环,这是您的选择。

#1


2  

Very little of the GLib code requires the main loop, timers for example are implemented using the system's normal timestamp.

很少的GLib代码需要主循环,例如,计时器是使用系统的正常时间戳实现的。

The code that does require the main loop will reference it, such as the IO Channels. Even then you can see that it's possible to use the IO Channels with or without the main loop, it's your choice.

需要主循环的代码将引用它,比如IO通道。即使这样,您也可以看到,可以使用带有主循环的IO通道,也可以不带主循环,这是您的选择。