Movatterモバイル変換


[0]ホーム

URL:


Next:, Previous:, Up:Introduction   [Contents][Index]


22 Memory Management and Type Information

GCC uses some fairly sophisticated memory management techniques, whichinvolve determining information about GCC’s data structures from GCC’ssource code and using this information to perform garbage collection andimplement precompiled headers.

A full C++ parser would be too complicated for this task, so a limitedsubset of C++ is interpreted and special markers are used to determinewhat parts of the source to look at. Allstruct,unionandtemplate structure declarations that define data structuresthat are allocated under control of the garbage collector must bemarked. All global variables that hold pointers to garbage-collectedmemory must also be marked. Finally, all global variables that needto be saved and restored by a precompiled header must be marked. (Theprecompiled header mechanism can only save static variables if they’rescalar. Complex data structures must be allocated in garbage-collectedmemory to be saved in a precompiled header.)

The full format of a marker is

GTY (([option] [(param)], [option] [(param)] …))

but in most cases no options are needed. The outer double parenthesesare still necessary, though:GTY(()). Markers can appear:

Here are some examples of marking simple data structures and globals.

struct GTY(())tag{fields…};typedef struct GTY(())tag{fields…} *typename;static GTY(()) structtag *list;   /*points to GC memory */static GTY(()) intcounter;        /*save counter in a PCH */

The parser understands simple typedefs such astypedef structtag *name; andtypedef intname;.These don’t need to be marked.

However, in combination with GTY, avoid using typedefs such astypedef int_hash<…>name;for these generate infinite-recursion code.SeePR103157.Instead, you may usestructname : int_hash<…> {};,for example.

Sincegengtype’s understanding of C++ is limited, there areseveral constructs and declarations that are not supported insideclasses/structures marked for automatic GC code generation. Thefollowing C++ constructs produce agengtype error onstructures/classes marked for automatic GC code generation:

If you have a class or structure using any of the above constructs,you need to mark that class asGTY ((user)) and provide yourown marking routines (see sectionSupport for user-provided GC marking routines for details).

It is always valid to include function definitions inside classes.Those are always ignored bygengtype, as it only cares aboutdata members.


Next:Plugins, Previous:Standard Header File Directories, Up:Introduction   [Contents][Index]


[8]ページ先頭

©2009-2026 Movatter.jp