<> <> DIRECTORY BasicTime, Random, RPCLupine; TestLupineRuntimeImplBuffers: PROGRAM IMPORTS BasicTime, Random, RPCLupine = { <> bufferRec: TYPE = RECORD [ address: LONG POINTER, size: CARDINAL _ 0 ]; bufferArray: ARRAY [1..128] OF bufferRec; freeRover: CARDINAL _ 1; maxListSize: INT = 7; -- Maximum size kept in the cache <> Test: PROC = { startTime: BasicTime.GMT = BasicTime.Now[]; [] _ Random.Create[]; WHILE BasicTime.Period[startTime, BasicTime.Now[]] < 30 DO noAllocs: CARDINAL = Random.ChooseInt[min: 1, max: 5]; noScan: CARDINAL = Random.ChooseInt[min: noAllocs, max: noAllocs*3]; FOR free: CARDINAL IN [1..noScan] DO IF bufferArray[freeRover].size # 0 THEN { RPCLupine.DeAlloc[bufferArray[freeRover].address, bufferArray[freeRover].size]; bufferArray[freeRover].size _ 0; }; freeRover _ freeRover + 1; IF freeRover > 128 THEN freeRover _ 1; ENDLOOP; FOR alloc: CARDINAL IN [1..noAllocs] DO size: CARDINAL = Random.ChooseInt[min: 1, max: 8] * 256; address: LONG POINTER TO WORD ; probe: CARDINAL; address _ RPCLupine.Alloc[size]; probe _ Random.ChooseInt[min: 1, max: 128]; DO IF bufferArray[probe].size = 0 THEN { bufferArray[probe].size _ size; bufferArray[probe].address _ address; EXIT; }; probe _ probe + 1; IF probe > 128 THEN probe _ 1; ENDLOOP; ENDLOOP; ENDLOOP; FOR free: CARDINAL IN [1..128] DO IF bufferArray[free].size # 0 THEN { RPCLupine.DeAlloc[bufferArray[free].address, bufferArray[free].size]; bufferArray[free].size _ 0; }; ENDLOOP; }; }. <> <> <<>>