/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

  1. class 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. 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. -- Just enable now the `low_memory_strategy' at the beginning
  25. -- of the execution of your main:
  26. set_low_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. -- Allocate both a fixed size object (of class STRING) and a
  36. -- resizable object (of class NATIVE_ARRAY[CHARACTER]):
  37. foo := ("bar").twin
  38. long_loop := long_loop - 1
  39. end
  40. sedb_breakpoint
  41. -- Press key G now !
  42. io.put_string("Collector counter: ")
  43. io.put_integer(collector_counter)
  44. io.put_new_line
  45. io.put_string("Allocated bytes of memory: ")
  46. io.put_integer(allocated_bytes)
  47. io.put_new_line
  48. end
  49. end -- class EXAMPLE1