Next: , Previous: Header Dirs, Up: Top


22 Memory Management and Type Information

GCC uses some fairly sophisticated memory management techniques, which involve determining information about GCC's data structures from GCC's source code and using this information to perform garbage collection and implement precompiled headers.

A full C parser would be too complicated for this task, so a limited subset of C is interpreted and special markers are used to determine what parts of the source to look at. All struct and union declarations that define data structures that are allocated under control of the garbage collector must be marked. All global variables that hold pointers to garbage-collected memory must also be marked. Finally, all global variables that need to be saved and restored by a precompiled header must be marked. (The precompiled header mechanism can only save static variables if they're scalar. Complex data structures must be allocated in garbage-collected memory 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 parentheses are 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(()) struct tag *list;   /* points to GC memory */
     static GTY(()) int counter;        /* save counter in a PCH */

The parser understands simple typedefs such as typedef struct tag *name; and typedef int name;. These don't need to be marked.