Logo

Programming-Idioms

History of Idiom 209 > diff from v4 to v5

Edit summary for version 5 by Bart:
New Pascal implementation by user [Bart]

Version 4

2019-09-30, 11:24:33

Version 5

2019-10-02, 16:00:08

Idiom #209 Type with automatic deep deallocation

Declare a type t which contains a string s and an integer array n with variable size, and allocate a variable a of type t. Allocate v.s and v.n and set them to the values "Hello, world!" for s and [1,4,9,16,25], respectively. Deallocate v, automatically deallocating v.s and v.n (no memory leaks).

Idiom #209 Type with automatic deep deallocation

Declare a type t which contains a string s and an integer array n with variable size, and allocate a variable a of type t. Allocate v.s and v.n and set them to the values "Hello, world!" for s and [1,4,9,16,25], respectively. Deallocate v, automatically deallocating v.s and v.n (no memory leaks).

Code
type
  TDynIntArray = array of integer;
  TT = record
    s: string;
    n: TDynIntArray;
  end;
  PTT = ^TT;

var
  v: PTT;
begin
  v := New(PTT);
  v^.s := 'Hello world';
  v^.n := TDynIntArray.Create(1,4,9,16,25);
  Dispose(v);
end.