[fpc-pascal] Managed record questions

Maciej Izak hnb.code at gmail.com
Thu Mar 8 10:00:20 CET 2018


2018-03-08 9:13 GMT+01:00 Ryan Joseph <ryan at thealchemistguild.com>:

> The more efficient approach would clearly be something like:
>
> procedure MyProc;
> var
>         list: stack TList; // assume this allocates us on the stack like a
> record
> begin
>         list.Clear; // there’s no Create call so init the class some how
>         list.Add(x);
>         // Free() is called when MyProc goes out of scope
> end;


Small ad of mORMot (main author Arnaud Bouchez aka ab) :

with SynCommons module you have nice utils for such things:

procedure MyProc;
var
  list: TList;
begin
  with TAutoFree.One(list, TList.Create) do
  begin
    list.Add(x);
    { ... some other stuff with list here }
  end;  // <-- here is called list.Free
end;

There is also nice module AutoScope which uses management operators (!) by
Dmitriy Pomerantsev aka pda0:

https://github.com/pda0/AutoScope

-- 
Best regards,
Maciej Izak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20180308/bade462c/attachment-0001.html>


More information about the fpc-pascal mailing list