<div dir="ltr"><div>Hi Tomas</div><div><br></div><div>I refined the module "Bitmaps" a little bit. This code allocates variably sized bitmaps and makes sure the garbage collector collects them if no longer referenced. As Andreas pointed out: it is the responsibility of the module using "Bitmaps" to make the bitmaps globally reachable. If not, the allocated memory gets freed up more or less immediately...</div><div><br></div><div>I compiled the code with the emulator on a Mac</div><div><br></div><div>MODULE Bitmaps; (* jr/11apr17 *)</div><div><br></div><div>IMPORT SYSTEM, Kernel := KernelOSX;</div><div><br></div><div>TYPE</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>TypeTag = RECORD size, ext1, ext2, ext3, offset: INTEGER END;<span style="white-space:pre"> </span>(* see Project Oberon, figure 8.8 *)</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>Address = POINTER TO RECORD END;<span class="gmail-Apple-tab-span" style="white-space:pre">                         </span>(* this pointer will be redefined by TypeTag *)</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">     </span>Bitmap* = POINTER TO RECORD</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">            </span>width, height: INTEGER;</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                </span>tag: TypeTag;<span class="gmail-Apple-tab-span" style="white-space:pre">                                                 </span><span style="white-space:pre">     </span><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>(* type descriptor of the pointer "base" *)</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                </span>base: Address</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">  </span>END;</div><div><br></div><div><br></div><div>PROCEDURE New*(w, h: INTEGER): Bitmap;</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">    </span>VAR b: Bitmap;</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>BEGIN</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">          </span>NEW(b);</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                </span>IF b # NIL THEN</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>b.width := w; b.height := h;</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                  </span>(* the following code defines a type tag corresponding to ARRAY size OF BYTE *)</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                       </span>b.tag.size := (w+7) DIV 8 * h;<span class="gmail-Apple-tab-span" style="white-space:pre">                                                  </span>(* size of the bitmap in BYTEs *)</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                    </span>b.tag.offset := -1;<span class="gmail-Apple-tab-span" style="white-space:pre">                                           </span>  (* type has no pointers, important for GC *)</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>(* allocate memory and define its type *)</div><div><span style="white-space:pre">                     </span>Kernel.New(SYSTEM.VAL(INTEGER, b.base), SYSTEM.ADR(b.tag));  </div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>IF b.base = NIL THEN b := NIL END</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">              </span>END</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">    </span>RETURN b</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">       </span>END New;</div><div><br></div><div>END Bitmaps.</div><div><br></div><div>System.Free Bitmaps ~</div><div>ORP.Compile Bitmaps.Mod ~</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-04-07 17:41 GMT+02:00 Andreas Pirklbauer <span dir="ltr"><<a href="mailto:andreas_pirklbauer@yahoo.com" target="_blank">andreas_pirklbauer@yahoo.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="color:#000;background-color:#fff;font-family:Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:13px"><div id="m_6372015898147730019yui_3_16_0_ym19_1_1491579440053_2868" dir="ltr"><span id="m_6372015898147730019yui_3_16_0_ym19_1_1491579440053_2983">To be precise:</span></div><div id="m_6372015898147730019yui_3_16_0_ym19_1_1491579440053_2868" dir="ltr"><span><br></span></div><div id="m_6372015898147730019yui_3_16_0_ym19_1_1491579440053_2868" dir="ltr"><span id="m_6372015898147730019yui_3_16_0_ym19_1_1491579440053_3116">If you don't make dynamically allocated objects reachable via at least one global pointer variable, they simply won't be marked during the mark phase of the garbage collector, which means that they *will* be collected during the subsequent scan phase. That's the whole point of garbage collection...</span></div><div class="m_6372015898147730019qtdSeparateBR" id="m_6372015898147730019yui_3_16_0_ym19_1_1491579440053_2931"><br><br></div><div class="m_6372015898147730019qtdSeparateBR" id="m_6372015898147730019yui_3_16_0_ym19_1_1491579440053_2931"><br></div><div class="m_6372015898147730019yahoo_quoted" id="m_6372015898147730019yui_3_16_0_ym19_1_1491579440053_2872" style="display:block">  <div style="font-family:Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:13px" id="m_6372015898147730019yui_3_16_0_ym19_1_1491579440053_2871"> <div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px" id="m_6372015898147730019yui_3_16_0_ym19_1_1491579440053_2870"> <div dir="ltr" id="m_6372015898147730019yui_3_16_0_ym19_1_1491579440053_2869"> <font size="2" face="Arial" id="m_6372015898147730019yui_3_16_0_ym19_1_1491579440053_2873"> <hr size="1" id="m_6372015898147730019yui_3_16_0_ym19_1_1491579440053_2909"> <b><span style="font-weight:bold">From:</span></b> Andreas Pirklbauer <<a href="mailto:andreas_pirklbauer@yahoo.com" target="_blank">andreas_pirklbauer@yahoo.com</a>><br> <b><span style="font-weight:bold">To:</span></b> ETH Oberon and Related Systems <<a href="mailto:oberon@lists.inf.ethz.ch" target="_blank">oberon@lists.inf.ethz.ch</a>> <br><b><span style="font-weight:bold">Cc:</span></b> Andreas Pirklbauer <<a href="mailto:andreas_pirklbauer@yahoo.com" target="_blank">andreas_pirklbauer@yahoo.com</a>><br> <b><span style="font-weight:bold">Sent:</span></b> Friday, April 7, 2017 5:35 PM<br> <b><span style="font-weight:bold">Subject:</span></b> [Oberon] Fw: FPGA - Bitmaps.Mod<br> </font> </div> <div class="m_6372015898147730019y_msg_container" id="m_6372015898147730019yui_3_16_0_ym19_1_1491579440053_2932"><br><div id="m_6372015898147730019yiv0560424603"><div id="m_6372015898147730019yui_3_16_0_ym19_1_1491579440053_2934"><div style="color:#000;background-color:#fff;font-family:Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:13px" id="m_6372015898147730019yui_3_16_0_ym19_1_1491579440053_2933"><div id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_2588">...</div><span class=""><div id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_2588" dir="ltr"><br></div><div id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_2588" dir="ltr">4. If you want your objects to be automatically collected by the Oberon garbage collector, you must make it globally reachable via a global pointer. Then they will appear in mod.ptr in the module block which are used as roots for the garbage collector. (Oberon uses all named pointer variables in existence as roots<font face="ArialMT" size="2" id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_5223"> for the mark phase of the garbage collector. See Oberon.GC for the details. It simply calls Kernel.Mark(mod.ptr) for each loaded module mod.</font></div><div id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_2588" dir="ltr"><font face="ArialMT" size="2"><br></font></div><div id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_2588" dir="ltr"><br></div><div title="Page 106" id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_4475"><div id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_4476"><div id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_4477"><div title="Page 106" id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_4496"><div id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_4497"><div id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_4498"><div title="Page 106" id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_4517"><div id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_4518"><div id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_4519">
                
        
        
                <div title="Page 106" id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_4538">
                        <div id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_4539">
                                <div id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_4540">
                                        <div dir="ltr" id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_4541"><span style="font-size:10.000000pt;font-family:'ArialMT'" id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_4542"> <br id="m_6372015898147730019yiv0560424603yui_3_16_0_ym19_1_1491577030619_4543"></span></div>
                                </div>
                        </div>
                </div>
                                </div>
                        </div>
                </div>
                                </div>
                        </div>
                </div>
                                </div>
                        </div>
                </div></span></div></div></div><br><br></div> </div> </div>  </div></div></div><br>--<br>
<a href="mailto:Oberon@lists.inf.ethz.ch">Oberon@lists.inf.ethz.ch</a> mailing list for ETH Oberon and related systems<br>
<a href="https://lists.inf.ethz.ch/mailman/listinfo/oberon" rel="noreferrer" target="_blank">https://lists.inf.ethz.ch/<wbr>mailman/listinfo/oberon</a><br>
<br></blockquote></div><br></div>