| | 23 | [[Image(heap-object.png)]] |
| | 24 | |
| | 25 | A heap object always begins with a ''header'', defined by {{{StgHeader}}} in [http://darcs.haskell.org/ghc/includes/Closures.h Closures.h]: |
| | 26 | |
| | 27 | {{{ |
| | 28 | typedef struct { |
| | 29 | const struct _StgInfoTable* info; |
| | 30 | #ifdef PROFILING |
| | 31 | StgProfHeader prof; |
| | 32 | #endif |
| | 33 | #ifdef GRAN |
| | 34 | StgGranHeader gran; |
| | 35 | #endif |
| | 36 | } StgHeader; |
| | 37 | }}} |
| | 38 | |
| | 39 | The most important part of the header is the ''info pointer'', which points to the info table for the closure. In the default build, this is all the header contains, so a header is normally just one word. In other builds, the header may contain extra information: eg. in a profilnig build it also contains information about who built the closure. |
| | 40 | |
| | 41 | Most of the runtime is insensitive to the size of {{{StgHeader}}}; that is, we are careful not to hardcode the offset to the payload anywhere, instead we use C struct indexing or {{{sizeof(StgHeader)}}}. This makes it easy to extend {{{StgHeader}}} with new fields if we need to. |