[Oberon] Dynamically sized allocation with NEW()
Tomas Kral
thomas.kral at email.cz
Tue Jan 15 17:52:05 CET 2019
On Mon, 14 Jan 2019 22:34:03 +0100
Andreas Pirklbauer <andreas_pirklbauer at yahoo.com> wrote:
> NEW(F.raster, NofBytes);
Hi, very interesting.
Is this allocated on the heap, or stack?
I am also interested in the other world without dynamic allocation,
i.e. NEW(p);
Can we also toy with some allocation templates
based on NEW(p);
MODULE Heap;
IMPORT S := SYSTEM;
TYPE
Size = INTEGER;
Block = INTEGER;
Buf16 = POINTER TO S16;
Buf32 = POINTER TO S32;
Buf64 = POINTER TO S64;
Buf128 = POINTER TO S128;
Buf256 = POINTER TO S256;
Buf512 = POINTER TO S512;
Buf1024 = POINTER TO S1024;
S16 = RECORD s: ARRAY 16 OF BYTE END ;
S32 = RECORD s: ARRAY 32 OF BYTE END ;
S64 = RECORD s: ARRAY 64 OF BYTE END ;
S128 = RECORD s: ARRAY 128 OF BYTE END ;
S256 = RECORD s: ARRAY 256 OF BYTE END ;
S512 = RECORD s: ARRAY 512 OF BYTE END ;
S1024 = RECORD s: ARRAY 1024 OF BYTE END ;
VAR buf16: Buf16; ... buf1024: Buf104;
PROCEDURE Alloc*(sz: Size; VAR b: Block)
BEGIN
IF sz < 16 THEN NEW(Buf16); b := S.VAL(Block, Buf16)
ELSIF sz < 32 THEN NEW(Buf32); b := S.VAL(Block, Buf32)
...
ELSIF sz < 1024 THEN NEW(Buf1024); b := S.VAL(Block, Buf1024)
ELSE b := NIL
END
END Alloc;
END Heap;
--
Tomas Kral <thomas.kral at email.cz>
More information about the Oberon
mailing list