about summary refs log tree commit diff stats
path: root/js/map-maker/imgs/extracted-1688-map/MapPartsWhite/trees_white/13.png
blob: c2622365af3002ff143f046e8a033ca48f40770a (plain)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 14 00 00 00 1b 08 06 00 00 00 7c df af .PNG........IHDR.............|..
0020 d8 00 00 01 fe 49 44 41 54 78 da dd d4 41 48 d3 61 18 c7 f1 d5 16 28 09 5d dc 3a c8 0c 3d 04 26 .....IDATx...AH.a.....(.].:..=.&
0040 46 84 42 48 28 82 5e 12 bd 24 11 24 84 b2 8b e0 08 22 51 62 5d f2 60 e4 61 a2 c7 a1 88 c2 a0 8b F.BH(.^..$.$....."Qb].`.a.......
0060 14 8a 90 2c 8a 0e 91 2c 12 07 0a 92 82 83 88 c0 43 21 28 6a d6 fa 3d f0 15 fe 44 f9 5f fe a5 43 ...,...,........C!(j..=...D._..C
0080 83 0f 9b 63 ef cf f7 7d de e7 f9 fb 7c ff fa 95 cb e5 ce 48 54 ce 1f 57 e0 6d f9 2e cf a4 d2 6b ...c...}....|......HT..W.m.....k
00a0 d8 09 b9 27 7b b2 2d f7 bd 06 d6 cb bc ec b3 cb 98 d7 c0 2b f2 92 b0 1f f2 c8 6b e0 29 3b 26 61 ...'{.-............+......k.);&a
00c0 df 64 52 42 5e 43 ef 12 b8 22 19 59 b2 52 78 09 6c 92 0d 79 27 cb f2 55 d2 92 90 c6 bf 0d 0b d1 .dRB^C...".Y.Rx.l..y'..U........
00e0 83 59 02 2d 68 4d 76 b8 a8 19 b7 80 1a a9 e6 73 81 4c 70 5c bb 94 45 79 2e 29 99 93 2f 74 40 c1 .Y.-hMv........s.Lp\..Ey.)../t@.
0100 61 81 d7 e5 09 0b df 53 33 7b 7f e3 f8 db 6e bd 05 55 6e 3b 0c cb 1d a6 62 4c ba f0 41 16 08 9e a......S3{....n..Un;....bL..A...
0120 92 0a 46 32 90 6f ed ca 6c 4a f8 7c 96 63 67 f8 47 56 86 66 b9 84 26 76 5b 2d a7 f3 09 2f 67 f4 ..F2.o..lJ.|.cg.GV.f..&v[-.../g.
0140 ac 5d 5e c9 5b 59 a5 86 1f 29 51 ad f8 dd 82 4a a4 43 66 b9 d1 2c 3b ec c7 08 7a 25 c2 00 c4 9d .]^.[Y...)Q....J.Cf..,;...z%....
0160 01 85 52 2a 57 f9 81 2d 7a ca ed 5a ab ac 73 c3 03 88 13 38 24 7d 32 6c 93 74 10 66 45 7e c1 b1 ..R*W..-z..Z..s....8$}2l.t.fE~..
0180 3e cb 16 37 6d 53 72 83 80 34 bb 5c 77 3c 2c f6 e9 49 3b 49 d0 b9 bb 73 2c ac e0 a6 2f db b3 4f >..7mSr..4.\w<,..I;I...s,.../..O
01a0 5a 65 90 b1 4b 51 af 71 79 c8 29 5a 78 22 f9 ff 54 b3 72 8e dc 2d 0f e4 31 47 8b d3 3e ed 72 4b Ze..KQ.qy.)Zx"..T.r..-..1G..>.rK
01c0 1a a4 ce 46 8f de 2d fa 5d 60 31 bb b4 c5 d3 f2 5a 92 d2 c3 e2 6b 2c be 49 68 84 9e 8d d9 66 7e ...F..-.]`1.....Z....k,.Ih....f~
01e0 0d 0b f0 23 db 59 9d e3 fb 20 c7 1e a3 b6 bb b2 49 dd ec c2 9a dd 5a e5 a4 35 27 41 6d 32 ca 2d ...#.Y..........I.....Z..5'Am2.-
0200 7f 62 52 12 ec f0 a2 9d 28 df 29 29 a2 d0 51 5a 21 c9 83 b5 d3 26 e8 28 cf bf 0b d4 2b ec fb 2f .bR.....(.))..QZ!....&.(....+../
0220 5f 3f 01 ea f6 6c 6c 19 e8 51 ae 00 00 00 00 49 45 4e 44 ae 42 60 82 _?...ll..Q.....IEND.B`.
d3fb68cc6fd70f90fff'>^
4aba7421f ^


7e7c514df ^

4aba7421f ^
f73cec7f0 ^
4aba7421f ^




8bed8efc3 ^
7e7c514df ^

1c0c80ef2 ^






7e7c514df ^
afd8ca2f1 ^


0b44d812f ^
0f2aa053d ^
0b44d812f ^
0f2aa053d ^
0b44d812f ^
1c0c80ef2 ^
0b44d812f ^
1c0c80ef2 ^
4aba7421f ^




7e7c514df ^
0b44d812f ^
e27ab3673 ^
4aba7421f ^
3ea644690 ^
4aba7421f ^


7e7c514df ^

0b44d812f ^
4aba7421f ^
7e7c514df ^


0b44d812f ^


7e7c514df ^




0b44d812f ^

7e7c514df ^






4aba7421f ^




0b44d812f ^
4aba7421f ^





d63e8e5d1 ^
0b44d812f ^
4aba7421f ^


afd8ca2f1 ^
4aba7421f ^



7e7c514df ^

0b44d812f ^
7e7c514df ^



4aba7421f ^
7956737ef ^



3ea644690 ^
7956737ef ^











1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
                          
                       

                          


                      
  
 
 
                                                   
 
 


            

                                                               
 
                                                                          




                                                                            
                                                                              

                                                      






                                                                             
                                                                             


                                                                            
                                                                 
 
                                                                              
                                                                           
                                                                  
                                                                           
                                                                      
                




                
                                                                       
                                                                         
                                                                         
 
                   


                                              

                                                                       
                                                              
 


                                                                              


                                                                              




                                                                          

                                                                      






                                                                              




                
                                                                          





                                                                            
                                                                           
                                  


                                                                             
                                                                             



                                

               
                                                                        



                                                                            
 



                       
                                                                        











                                                                              
==========================
Nim's Garbage Collector
==========================

:Author: Andreas Rumpf
:Version: |nimversion|

..


  "The road to hell is paved with good intentions."


Introduction
============

This document describes how the GC works and how to tune it for
(soft) `realtime systems`:idx:.

The basic algorithm is *Deferred Reference Counting* with cycle detection.
References on the stack are not counted for better performance (and easier C
code generation). The GC **never** scans the whole heap but it may scan the
delta-subgraph of the heap that changed since its last run.


The GC is only triggered in a memory allocation operation. It is not triggered
by some timer and does not run in a background thread.

To force a full collection call ``GC_fullCollect``. Note that it is generally
better to let the GC do its work and not enforce a full collection.


Cycle collector
===============

The cycle collector can be en-/disabled independently from the other parts of
the GC with ``GC_enableMarkAndSweep`` and ``GC_disableMarkAndSweep``. The
compiler analyses the types for their possibility to build cycles, but often
it is necessary to help this analysis with the ``acyclic`` pragma (see
`acyclic <manual.html#acyclic-pragma>`_ for further information).

You can also use the ``acyclic`` pragma for data that is cyclic in reality and
then break up the cycles explicitly with ``GC_addCycleRoot``. This can be a
very valuable optimization; the Nim compiler itself relies on this
optimization trick to improve performance. Note that ``GC_addCycleRoot`` is
a quick operation; the root is only registered for the next run of the
cycle collector.


Realtime support
================

To enable realtime support, the symbol `useRealtimeGC`:idx: needs to be
defined via ``--define:useRealtimeGC`` (you can put this into your config
file as well). With this switch the GC supports the following operations:

.. code-block:: nim
  proc GC_setMaxPause*(MaxPauseInUs: int)
  proc GC_step*(us: int, strongAdvice = false)

The unit of the parameters ``MaxPauseInUs`` and ``us`` is microseconds.

These two procs are the two modus operandi of the realtime GC:

(1) GC_SetMaxPause Mode

    You can call ``GC_SetMaxPause`` at program startup and then each triggered
    GC run tries to not take longer than ``MaxPause`` time. However, it is
    possible (and common) that the work is nevertheless not evenly distributed
    as each call to ``new`` can trigger the GC and thus take  ``MaxPause``
    time.

(2) GC_step Mode

    This allows the GC to perform some work for up to ``us`` time. This is
    useful to call in a main loop to ensure the GC can do its work. To
    bind all GC activity to a ``GC_step`` call, deactivate the GC with
    ``GC_disable`` at program startup.

These procs provide a "best effort" realtime guarantee; in particular the
cycle collector is not aware of deadlines yet. Deactivate it to get more
predictable realtime behaviour. Tests show that a 2ms max pause
time will be met in almost all cases on modern CPUs unless the cycle collector
is triggered.


Time measurement
----------------

The GC's way of measuring time uses (see ``lib/system/timers.nim`` for the
implementation):

1) ``QueryPerformanceCounter`` and ``QueryPerformanceFrequency`` on Windows.
2) ``mach_absolute_time`` on Mac OS X.
3) ``gettimeofday`` on Posix systems.

As such it supports a resolution of nanoseconds internally; however the API
uses microseconds for convenience.


Define the symbol ``reportMissedDeadlines`` to make the GC output whenever it
missed a deadline. The reporting will be enhanced and supported by the API in
later versions of the collector.


Tweaking the GC
---------------

The collector checks whether there is still time left for its work after
every ``workPackage``'th iteration. This is currently set to 100 which means
that up to 100 objects are traversed and freed before it checks again. Thus
``workPackage`` affects the timing granularity and may need to be tweaked in
highly specialized environments or for older hardware.


Keeping track of memory
-----------------------

If you need to pass around memory allocated by Nim to C, you can use the
procs ``GC_ref`` and ``GC_unref`` to mark objects as referenced to avoid them
being freed by the GC. Other useful procs from `system <system.html>`_ you can
use to keep track of memory are:

* getTotalMem(): returns the amount of total memory managed by the GC.
* getOccupiedMem(): bytes reserved by the GC and used by objects.
* getFreeMem(): bytes reserved by the GC and not in use.

In addition to ``GC_ref`` and ``GC_unref`` you can avoid the GC by manually
allocating memory with procs like ``alloc``, ``allocShared``, or
``allocCStringArray``. The GC won't try to free them, you need to call their
respective *dealloc* pairs when you are done with them or they will leak.