PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/memory/example2.e

http://github.com/tybor/Liberty
Specman e | 49 lines | 27 code | 4 blank | 18 comment | 0 complexity | 7c43286d7d3a9da8dea3075ca1fae94e MD5 | raw file
 1class EXAMPLE2
 2	--
 3	-- Here is a little cookbook for people using very large computers.
 4	-- We suppose here that the goal is to minimize execution time (i.e.
 5	-- we suppose now that you have a _lot_ of available memory).
 6	--
 7	-- Note: it is usually interesting to compare the execution time of this
 8	-- example with/without the SmartEiffel garbage collector:
 9	--    compile -boost        example2
10	--    compile -boost -no_gc example2
11	--
12	-- Hint: when the -no_gc flag is used, there is one C malloc for
13	-- each object.
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			-- Here, we suppose that you have a _LOT_ of memory and our
28			-- prediction is to push ceils at the maximum:
29			set_high_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				foo := ("bar").twin
39				long_loop := long_loop - 1
40			end
41			io.put_string("Collector counter: ")
42			io.put_integer(collector_counter)
43			io.put_new_line
44			io.put_string("Allocated bytes of memory: ")
45			io.put_integer(allocated_bytes)
46			io.put_new_line
47		end
48
49end -- class EXAMPLE2