PageRenderTime 32ms CodeModel.GetById 27ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/memory/example1.e

http://github.com/tybor/Liberty
Specman e | 53 lines | 28 code | 4 blank | 21 comment | 0 complexity | 7c4367d31e7ba401cc839e00891e280b MD5 | raw file
 1class EXAMPLE1
 2	--
 3	-- Here is a little cookbook for people using very small computers.
 4	-- We suppose here that the goal is to save memory.
 5	--
 6	-- Note: to see how many times the garbage collector is triggered,
 7	-- keep in mind that you can use the -gc_info flag as in:
 8	--
 9	--    compile -gc_info -boost example1
10	--
11	-- Also note that you can run this example under the debugger:
12	--
13	--    compile -gc_info -sedb -no_check example1
14	--
15
16insert
17	MEMORY
18
19creation {ANY}
20	my_main
21
22feature {ANY}
23	my_main is
24		local
25			long_loop: INTEGER; foo: STRING
26		do
27			-- Just enable now the `low_memory_strategy' at the beginning
28			-- of the execution of your main:
29			set_low_memory_strategy
30			from
31				long_loop := 50_000
32				-- Please uncomment the following line to have more time
33				-- to check memory consumption:
34				-- long_loop := 10_000_000;
35			until
36				long_loop <= 0
37			loop
38				-- Allocate both a fixed size object (of class STRING) and a
39				-- resizable object (of class NATIVE_ARRAY[CHARACTER]):
40				foo := ("bar").twin
41				long_loop := long_loop - 1
42			end
43			sedb_breakpoint
44			-- Press key G now !
45			io.put_string("Collector counter: ")
46			io.put_integer(collector_counter)
47			io.put_new_line
48			io.put_string("Allocated bytes of memory: ")
49			io.put_integer(allocated_bytes)
50			io.put_new_line
51		end
52
53end -- class EXAMPLE1