1 '' examples/manual/memory/allocate.bas 2 '' 3 '' NOTICE: This file is part of the FreeBASIC Compiler package and can't 4 '' be included in other distributions without authorization. 5 '' 6 '' See Also: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgAllocate 7 '' -------- 8 9 '' This program uses the ALLOCATE(...) function to create a buffer of 15 integers that is 10 '' then filled with the first 15 numbers of the Fibonacci Sequence, then output to the 11 '' screen. Note the call to DEALLOCATE(...) at the end of the program. 12 13 Const integerCount As Integer = 15 14 15 '' Try allocating memory for a number of integers. 16 '' 17 Dim buffer As Integer Ptr 18 buffer = Allocate(integerCount * SizeOf(Integer)) 19 20 If (0 = buffer) Then 21 Print "Error: unable to allocate memory, quitting." 22 End -1 23 End If 24 25 '' Prime and fill the memory with the fibonacci sequence. 26 '' 27 buffer[0] = 0 28 buffer[1] = 1 29 For i As Integer = 2 To integerCount - 1 30 buffer[i] = buffer[i - 1] + buffer[i - 2] 31 Next 32 33 '' Display the sequence. 34 '' 35 For i As Integer = 0 To integerCount - 1 36 Print buffer[i] ; 37 Next 38 39 Deallocate(buffer) 40 End 0