/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

  1. class 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. insert
  16. MEMORY
  17. creation {ANY}
  18. my_main
  19. feature {ANY}
  20. my_main is
  21. local
  22. long_loop: INTEGER; foo: STRING
  23. do
  24. -- Here, we suppose that you have a _LOT_ of memory and our
  25. -- prediction is to push ceils at the maximum:
  26. set_high_memory_strategy
  27. from
  28. long_loop := 50_000
  29. -- Please uncomment the following line to have more time
  30. -- to check memory consumption:
  31. -- long_loop := 10_000_000;
  32. until
  33. long_loop <= 0
  34. loop
  35. foo := ("bar").twin
  36. long_loop := long_loop - 1
  37. end
  38. io.put_string("Collector counter: ")
  39. io.put_integer(collector_counter)
  40. io.put_new_line
  41. io.put_string("Allocated bytes of memory: ")
  42. io.put_integer(allocated_bytes)
  43. io.put_new_line
  44. end
  45. end -- class EXAMPLE2