Eclipse 有两个 C/C++ 索引器(快速和完整):有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/763837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 17:10:27  来源:igfitidea点击:

Eclipse has two C/C++ indexers (fast & full): what's the difference?

c++ceclipseeclipse-cdtindexer

提问by Rabarberski

Eclipse CDT provides two indexers for C/C++ code (Preferences > C/C++ > Indexer). Does anybody know what the exact difference is between these two?

Eclipse CDT 为 C/C++ 代码提供了两个索引器(Preferences > C/C++ > Indexer)。有谁知道这两者之间的确切区别是什么?

The help file isn't exactly enlightening:

帮助文件并不完全具有启发性:

"CDT supports the contribution of additional indexers, with 2 indexers being provided with the default CDT release:

  • Fast C/C++ Indexer : provides fastest indexing capabilities - both declarations and cross reference information. This is the recommended indexer.

  • Full C/C++ Indexer : provides even more accurate indexing capabilities at the cost of performance - both declarations and cross reference information."

“CDT 支持其他索引器的贡献,默认 CDT 版本提供了 2 个索引器:

  • 快速 C/C++ 索引器:提供最快的索引功能 - 声明和交叉引用信息。这是推荐的索引器。

  • 完整的 C/C++ 索引器:以牺牲性能为代价提供更准确的索引功能 - 声明和交叉引用信息。”

What does it mean to be more accurate: does it index more things, and if so which ones?

准确意味着什么:它是否索引更多的东西,如果是,是哪些?

回答by dagorym

Here is an excerpt from the CDT page describing their parsing and indexing(CDT/designs/Overview of Parsing). It gives a pretty good description of what the differences are and where the fast indexer can fail:

这是 CDT 页面的摘录,描述了它们的解析和索引(CDT/designs/Overview of Parsing)。它很好地描述了不同之处以及快速索引器可能失败的地方:

Parsing and binding resolution is a slow process, this is a problem because the user expects code editing features such as content assist to be fast. For this reason CDT stores binding information in an on-disk cache called “the index” or “the PDOM” (Persisted Document Object Model) in order to be able to provide features that respond quickly to user requests.

Building the index involves parsing all the code in a project, resolving all the bindings and writing those bindings to the index. The index is then incrementally updated every time the user edits a file.

Older versions of CDT support three different indexing modes, fast indexing, full indexing and no indexing. The default setting being the fast indexer because indexing a large project can be a time consuming process. The difference between the fast and full indexers is that the fast indexer will skip header files that have already been parsed once, while the full indexer will always re-parse a header file every time it is included. However it is important to understand that the full indexer, despite its name, is still not fully accurate.

When a header file is included in a source file it is subject to any macros that have been defined at that point. Some library headers use macros in conjunction with preprocessor conditionals (#ifdefs) to partially include a header file. Sometimes such a header file is included more than once in a project, if the macros that the header depends on are different each time the header is included then different parts of the header may be included in different source files. Neither indexer will be accurate in this scenario because it will only index the header the first time it is encountered.

The Full indexer will re-parse headers it has already encountered, but it will not re-index them. Therefore source files that include a header may be parsed more accurately, but the header itself will only be indexed the one time. The full indexer is much slower than the fast indexer because of the extra parsing it does, but it is only marginally more accurate. For this reason the Full indexer is not recommended and has been removed from the current version of CDT.

Each project has a single PDOM associated with it. The PDOM is stored on disk as a flat binary file. The indexer will only index headers that are included by source files, so if there is a .h file in the project that is not being included by any .c or .cpp file, then normally it won't get indexed. However there is a preference setting for indexing all files in the project.

解析和绑定解析是一个缓慢的过程,这是一个问题,因为用户希望内容辅助等代码编辑功能很快。因此,CDT 将绑定信息存储在称为“索引”或“PDOM”(持久文档对象模型)的磁盘缓存中,以便能够提供快速响应用户请求的功能。

构建索引涉及解析项目中的所有代码、解析所有绑定并将这些绑定写入索引。每次用户编辑文件时,索引都会增量更新。

旧版本的 CDT 支持三种不同的索引模式,快速索引、完整索引和无索引。默认设置是快速索引器,因为索引大型项目可能是一个耗时的过程。快速索引器和完整索引器的区别在于快速索引器会跳过已经解析过一次的头文件,而完整索引器每次都会重新解析一个头文件。然而,重要的是要了解完整索引器,尽管它的名字,仍然不完全准确。

当头文件包含在源文件中时,它受制于当时定义的任何宏。一些库头文件将宏与预处理器条件 (#ifdefs) 结合使用以部分包含头文件。有时这样的头文件在一个项目中被包含不止一次,如果头文件依赖的宏在每次被包含时都不同,那么头文件的不同部分可能包含在不同的源文件中。在这种情况下,这两个索引器都不准确,因为它只会在第一次遇到标题时对其进行索引。

完整索引器将重新解析它已经遇到的标头,但不会重新索引它们。因此,包含标题的源文件可能会被更准确地解析,但标题本身只会被索引一次。完整索引器比快速索引器慢得多,因为它进行了额外的解析,但它只是稍微准确一些。出于这个原因,不推荐使用完整索引器,并且已从 CDT 的当前版本中删除。

每个项目都有一个与之关联的 PDOM。PDOM 作为平面二进制文件存储在磁盘上。索引器只会索引源文件包含的头文件,所以如果项目中有一个 .h 文件没有被任何 .c 或 .cpp 文件包含,那么它通常不会被索引。但是,有一个用于索引项目中所有文件的首选项设置。

回答by Hrvoje Prge?a

I believe it always reparses any found/included files without "caching". The reason if that the contents of the files might depend on the preprocessor definitions so it is always reparsed. Fast parser assumes nothing has changed since the file was first encountered.

我相信它总是在没有“缓存”的情况下重新解析任何找到/包含的文件。文件的内容可能取决于预处理器定义的原因,所以它总是被重新解析。快速解析器假定自从第一次遇到文件以来没有任何变化。

(but I could be wrong)

(但我可能是错的)

回答by greyfade

Does anybody know what the exact difference is between these two?

有谁知道这两者之间的确切区别是什么?

In my experience, about 32MB heap.

根据我的经验,大约 32MB 堆。