[Oberon] Dynamically sized allocation with NEW()
Andreas Pirklbauer
andreas_pirklbauer at yahoo.com
Mon Jan 14 22:34:03 CET 2019
>> Am 02.08.2018 um 20:10 schrieb Tomas Kral <thomas.kral at email.cz>:
>>
>> FontDesc = RECORD
>> raster: ARRAY 2000 OF BYTE
>> END;
>> LargeFontDesc = RECORD (FontDesc)
>> extRaster: ARRAY 1000 OF BYTE
>> END;
>> VAR F: = ; LF: LargeFont;
>> IF len<2000 THEN NEW (F) ELSE NEW(LF); F := LF END;
>>
>> Rather clever, the below two pointers are needed, correct?
>>
>> Font = POINTER TO FontDesc;
>> LargeFont = POINTER TO LargeFontDesc;
>>
Just as an FYI: In EO this is (now) done as follows:
TYPE Raster = POINTER TO RasterArray;
RasterArray = ARRAY OF BYTE;
Font* = POINTER TO FontDesc;
FontDesc* = RECORD
...
raster: Raster (*dynamic open array*)
END ;
PROCEDURE This*(name: ARRAY OF CHAR): Font;
VAR F: Font;
...
BEGIN
...
NEW(F); NEW(F.raster, NofBytes);
...
END This;
i.e. using dynamically allocated open *arrays* for the font raster
and therefore without the need for LargeFont and LargeFontDesc.
More information about the Oberon
mailing list