tarctypesections.nim 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. discard """
  2. output: "MEM 0"
  3. cmd: "nim c --gc:arc $file"
  4. """
  5. type
  6. RefNode = ref object
  7. le, ri: RefNode
  8. name: char
  9. proc edge0(a, b: RefNode) =
  10. if a.le == nil: a.le = b
  11. else: a.ri = b
  12. proc createNode0(name: char): RefNode =
  13. new result
  14. result.name = name
  15. proc main0 =
  16. let r = createNode0('R')
  17. let c = createNode0('C')
  18. c.edge0 r
  19. type
  20. NodeDesc = object
  21. le, ri: Node
  22. name: char
  23. Node = ref NodeDesc
  24. proc edge(a, b: Node) =
  25. if a.le == nil: a.le = b
  26. else: a.ri = b
  27. proc createNode(name: char): Node =
  28. new result
  29. result.name = name
  30. proc main =
  31. let r = createNode('R')
  32. let c = createNode('C')
  33. c.edge r
  34. type
  35. NodeB = ref NodeBo
  36. NodeBo = object
  37. le, ri: NodeB
  38. name: char
  39. proc edge(a, b: NodeB) =
  40. if a.le == nil: a.le = b
  41. else: a.ri = b
  42. proc createNodeB(name: char): NodeB =
  43. new result
  44. result.name = name
  45. proc mainB =
  46. let r = createNodeB('R')
  47. let c = createNodeB('C')
  48. c.edge r
  49. let memB = getOccupiedMem()
  50. main0()
  51. main()
  52. mainB()
  53. echo "MEM ", getOccupiedMem() - memB