home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 7.ddi / HEAP.ZIP / MEMTEST.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-06-10  |  10.3 KB  |  500 lines

  1. page 75,132
  2. %title "Object Oriented Memory Management System - TASM 3.0"
  3. %subttl "Testing/Benchmark module"
  4. ; Copyright (c) 1991 By Borland International, Inc.
  5.  
  6. ifndef MDL
  7.     display "Error: This module requires that you provide a memory model"
  8.     display "    definition on the command line. I.E. /dMDL=SMALL."
  9.     display "Also, /M must be given on the command line to enable multiple"
  10.     display "    passes."
  11.  
  12. MDL equ <SMALL>
  13.  
  14. endif
  15.  
  16.  
  17.  
  18. ModuleVersion EQU "0.32"
  19.  
  20. jumps
  21. page
  22. locals @@
  23.  
  24. ; Things to check:
  25. ;   Check the effect of /ML  on generated macros for method calls.
  26.  
  27.  
  28. .model MDL,pascal
  29. .stack 1000h
  30. .code
  31.  
  32. CR  = 0DH
  33. LF  = 0AH
  34.  
  35. ; Int 21 DOS calls
  36. DOSINT             =   21H
  37. DOSRESIZEBLOCK     =   4AH
  38. DOSPRINTSTRING     =   09H
  39. DOSTERMINATE       =   4CH
  40.  
  41. include vmtutil.inc
  42.  
  43. ; Include the display routines
  44.    include display.inc
  45.  
  46. ; Include definitions of the memory system objects
  47.    include mem.inc
  48.  
  49.  
  50. ; Create an advanced decendant of the memory_system !
  51.  
  52. memory_system_advanced STRUC memory_system METHOD \
  53.          init:mptr=memory_system_advanced_init,\
  54.          virtual show:mptr=memory_system_advanced_show
  55.   diskhandle dw ?
  56. memory_system_advanced ends
  57.  
  58. memory_system_advanced_init proc
  59.         ; Must fill in the VMT pointer
  60.          mov  [ds:si.@Mptr_memory_system],offset @TableAddr_memory_system_advanced
  61.          mov  [ds:si.root],0
  62.          mov  [ds:si.last],0
  63.          mov  [ds:si.rover],0
  64.          mov  [ds:si.freespace],0
  65.          mov  [ds:si.usedspace],0
  66.          ret
  67. memory_system_advanced_init endp
  68.  
  69. .data
  70. msas_advanced db "Advanced $"
  71. .code
  72. memory_system_advanced_show proc
  73.          push  ds
  74.          mov   ax,@data
  75.          mov   ds,ax
  76.          mov   dx,offset msas_advanced
  77.          mov   ah,DOSPRINTSTRING
  78.          int   21h
  79.          pop   ds
  80.          call  +@Table_memory_system|show
  81.          ret
  82. memory_system_advanced_show endp
  83.  
  84.  
  85. ; Make the advanced memory system VMT.
  86. MAKE_VMT
  87.  
  88.  
  89. .data
  90.  
  91. ; Declare an instance of the memory system. Note that multiple memory
  92. ; system instances can be declared and if each is initialized with AX
  93. ; other than zero, they each will manage separate heaps.
  94. memory   memory_system {}
  95.  
  96.  
  97. memorya  memory_system_advanced {@Mptr_memory_system = @TableAddr_memory_system_advanced}
  98.  
  99. Psp      dw ?               ; Our PSP
  100. LastSeg  dw seg zzlastseg   ; Segment of the last segment in memory
  101.  
  102. block1   dw ?
  103. block2   dw ?
  104. block3   dw ?
  105. block4   dw ?
  106.          dw 20000 dup (?)
  107.  
  108. .code
  109. start_:
  110.  
  111.      ; Load our data segment
  112.      mov  ax,@data
  113.      mov  ds,ax
  114.  
  115.      ; Store the original PSP in case it is needed.
  116.      mov  [Psp],es
  117.  
  118.      ; Have to give up extra memory that we don't need
  119.      ; so the memory system objects can get blocks of memory.
  120.      mov  bx,[LastSeg]
  121.      mov  ax,es
  122.      sub  bx,ax    ; Size of program as a number of segments is in BX
  123.      mov  ah,DOSRESIZEBLOCK
  124.      int  DOSINT
  125.  
  126.  
  127.      ; Initialize the memory system
  128.      mov  si,offset memory
  129.  
  130.  
  131. comment ~
  132.      ; Only allow memory system to grab 300 paragraphs of memory
  133.      mov  ax,300
  134.  
  135.  
  136.      ; Set ES to point to the virtual tables!
  137.      LoadVMTSeg  ES
  138.      call [si] method memory_system:init
  139.      call [si] method memory_system:show
  140.  
  141.      mov  cx,100
  142.      mov  di,offset block1
  143. t1:
  144.      mov  ax,2
  145.      call [si] method memory_system:alloc
  146.      mov  [di],ax
  147.      add  di,2
  148.      loop t1
  149.  
  150.      call [si] method memory_system:show
  151.      call CRLF
  152.      call CRLF
  153.  
  154.      mov  cx,100
  155.      mov  di,offset block1
  156. t2:
  157.      mov  ax,[di]
  158.      call [si] method memory_system:free
  159.      mov  word ptr [di],0
  160.      add  di,2
  161.      loop t2
  162.  
  163.      call [si] method memory_system:show
  164.      call CRLF
  165.      call CRLF
  166.  
  167.  
  168.  
  169.      mov  ax,90
  170.      call [si] method memory_system:alloc
  171.      mov  [block1],ax
  172.      call [si] method memory_system:show
  173.  
  174.      mov  ax,90
  175.      call [si] method memory_system:alloc
  176.      mov  [block2],ax
  177.      call [si] method memory_system:show
  178.  
  179.      mov  ax,90
  180.      call [si] method memory_system:alloc
  181.      mov  [block3],ax
  182.      call [si] method memory_system:show
  183.  
  184.  
  185.      mov  ax,[block2]
  186.      call [si] method memory_system:free
  187.      call [si] method memory_system:show
  188.  
  189.      mov  ax,[block1]
  190.      call [si] method memory_system:free
  191.      call [si] method memory_system:show
  192.  
  193.      mov  ax,[block3]
  194.      call [si] method memory_system:free
  195.      call [si] method memory_system:show
  196.      call CRLF
  197.      call CRLF
  198.  
  199. ~
  200.      ; Allow memory system to grab all the memory it can
  201.      mov  ax,0
  202.  
  203.  
  204.      ; Set ES to point to the virtual tables!
  205.      LoadVMTSeg  ES
  206.      call [si] method memory_system:init
  207.      call [si] method memory_system:show
  208.  
  209.  
  210. ; Test using memory_system:alloc and memory_block:markfree
  211. blockcount=2000
  212.  
  213.      ; Get 20 blocks of various sizes
  214.      mov  cx,blockcount
  215.      mov  di,offset block1
  216. again:
  217.      mov  ax,cx
  218.      and  ax,0fh
  219.      cmp  al,0
  220.      jne  again_2
  221. ;     call [si] method memory_system:show
  222. again_2:
  223.      inc  ax
  224.      inc  ax
  225.      call [si] method memory_system:alloc
  226.      mov  [di],ax
  227.      inc  di
  228.      inc  di
  229.      loop again
  230.  
  231. ;     call [si] method memory_system:show
  232. ;     call CRLF
  233. ;     call CRLF
  234.  
  235.      xor  si,si
  236.      ; Now free up half of them
  237.      mov  cx,blockcount/2
  238.      mov  di,offset block1
  239. again_3:
  240.      mov  ax,cx
  241.      and  ax,0fh
  242.      cmp  al,0
  243.      jne  again_4
  244. ;     call [si] method memory_system:show
  245. again_4:
  246.      mov  ax,[di]
  247.      mov  word ptr [di],0
  248.      cmp  ax,0
  249.      je   again_5
  250.      push ds
  251.      mov  ds,ax
  252.      call [si] method memory_block:MarkFree
  253.      pop  ds
  254. again_5:
  255.      add  di,4
  256.      loop again_3
  257.  
  258. ;     call [si] method memory_system:show
  259. ;     call CRLF
  260. ;     call CRLF
  261.  
  262.      ; Now free up all the rest
  263.      mov  cx,blockcount
  264.      mov  di,offset block1
  265. again_6:
  266.      mov  ax,cx
  267.      and  ax,0fh
  268.      cmp  al,0
  269.      jne  again_7
  270. ;     call [si] method memory_system:show
  271. again_7:
  272.      mov  ax,[di]
  273.      mov  word ptr [di],0
  274.      cmp  ax,0
  275.      je   again_8
  276.      push ds
  277.      mov  ds,ax
  278.      call [si] method memory_block:MarkFree
  279.      pop  ds
  280.  
  281. again_8:
  282.      add  di,2
  283.      loop again_6
  284.  
  285. ;     call [si] method memory_system:show
  286. ;     call CRLF
  287. ;     call CRLF
  288.  
  289.      mov  si,offset memory
  290.      ; Now allocate 13 very large blocks
  291.      mov  cx,13
  292.      mov  di,offset block1
  293. final:
  294.      mov  ax,2000
  295.      call [si] method memory_system:alloc
  296.      mov  [di],ax
  297.      add  di,2
  298.      loop final
  299.  
  300.  
  301. ;     call [si] method memory_system:show
  302. ;     call CRLF
  303. ;     call CRLF
  304.  
  305.      xor  si,si
  306.      mov  cx,13
  307.      mov  di,offset block1
  308. final2:
  309.      mov  ax,[di]
  310.      push ds
  311.      mov  ds,ax
  312.      call [si] method memory_block:MarkFree
  313.      pop  ds
  314.      add  di,2
  315.      loop final2
  316.  
  317.  
  318.      mov  si,offset memory
  319.       ; Now allocate 15 larger blocks
  320.      mov  cx,15
  321.      mov  di,offset block1
  322. final3:
  323.      mov  ax,2500
  324.      call [si] method memory_system:alloc
  325.      mov  [di],ax
  326.      add  di,2
  327.      loop final3
  328.  
  329.  
  330. ;     call [si] method memory_system:show
  331. ;     call CRLF
  332. ;     call CRLF
  333.  
  334.      xor  si,si
  335.      mov  cx,15
  336.      mov  di,offset block1
  337. final4:
  338.      mov  ax,[di]
  339.      cmp  ax,0
  340.      jz   final4b
  341.      push ds
  342.      mov  ds,ax
  343.      call [si] method memory_block:MarkFree
  344.      pop  ds
  345. final4b:
  346.      add  di,2
  347.      loop final4
  348.  
  349.      mov  si,offset memory
  350.  
  351. comment ~
  352. ; Test using memory_system:alloc and memory_system:free
  353. blockcount=2000
  354.  
  355.      ; Get 20 blocks of various sizes
  356.      mov  cx,blockcount
  357.      mov  di,offset block1
  358. again:
  359.      mov  ax,cx
  360.      and  ax,0fh
  361.      cmp  al,0
  362.      jne  again_2
  363. ;     call [si] method memory_system:show
  364. again_2:
  365.      inc  ax
  366.      inc  ax
  367.      call [si] method memory_system:alloc
  368.      mov  [di],ax
  369.      inc  di
  370.      inc  di
  371.      loop again
  372.  
  373. ;     call [si] method memory_system:show
  374. ;     call CRLF
  375. ;     call CRLF
  376.  
  377.      ; Now free up half of them
  378.      mov  cx,blockcount/2
  379.      mov  di,offset block1
  380. again_3:
  381.      mov  ax,cx
  382.      and  ax,0fh
  383.      cmp  al,0
  384.      jne  again_4
  385. ;     call [si] method memory_system:show
  386. again_4:
  387.      mov  ax,[di]
  388.      mov  word ptr [di],0
  389.      cmp  ax,0
  390.      je   again_5
  391.      call [si] method memory_system:free
  392. again_5:
  393.      add  di,4
  394.      loop again_3
  395.  
  396. ;     call [si] method memory_system:show
  397. ;     call CRLF
  398. ;     call CRLF
  399.  
  400.      ; Now free up all the rest
  401.      mov  cx,blockcount
  402.      mov  di,offset block1
  403. again_6:
  404.      mov  ax,cx
  405.      and  ax,0fh
  406.      cmp  al,0
  407.      jne  again_7
  408. ;     call [si] method memory_system:show
  409. again_7:
  410.      mov  ax,[di]
  411.      mov  word ptr [di],0
  412.      cmp  ax,0
  413.      je   again_8
  414.      call [si] method memory_system:free
  415. again_8:
  416.      add  di,2
  417.      loop again_6
  418.  
  419. ;     call [si] method memory_system:show
  420. ;     call CRLF
  421. ;     call CRLF
  422.  
  423.      ; Now allocate 13 very large blocks
  424.      mov  cx,13
  425.      mov  di,offset block1
  426. final:
  427.      mov  ax,2000
  428.      call [si] method memory_system:alloc
  429.      mov  [di],ax
  430.      add  di,2
  431.      loop final
  432.  
  433.  
  434. ;     call [si] method memory_system:show
  435. ;     call CRLF
  436. ;     call CRLF
  437.  
  438.      mov  cx,13
  439.      mov  di,offset block1
  440. final2:
  441.      mov  ax,[di]
  442.      call [si] method memory_system:free
  443.      add  di,2
  444.      loop final2
  445.  
  446.  
  447.      ; Now allocate 15 larger blocks
  448.      mov  cx,15
  449.      mov  di,offset block1
  450. final3:
  451.      mov  ax,2500
  452.      call [si] method memory_system:alloc
  453.      mov  [di],ax
  454.      add  di,2
  455.      loop final3
  456.  
  457.  
  458. ;     call [si] method memory_system:show
  459. ;     call CRLF
  460. ;     call CRLF
  461.  
  462.      mov  cx,15
  463.      mov  di,offset block1
  464. final4:
  465.      mov  ax,[di]
  466.      call [si] method memory_system:free
  467.      add  di,2
  468.      loop final4
  469.  
  470. ~
  471.      call [si] method memory_system:show
  472.      call CRLF
  473.      call CRLF
  474.      call [si] method memory_system:freeall
  475.      call [si] method memory_system:show
  476.      call CRLF
  477.      call CRLF
  478.  
  479.      ; Try the same calls with the advanced memory system object
  480.      mov  si,seg memorya
  481.      mov  ds,si
  482.      mov  si,offset memorya
  483.  
  484.      ; Set ES to point to the virtual tables!
  485.      LoadVMTSeg  ES,BX
  486.      call [si] method memory_system_advanced:init
  487.      call [si] method memory_system_advanced:show
  488.      call [si] method memory_system_advanced:freeall
  489.      mov  ah,DOSTERMINATE
  490.      int  DOSINT
  491.  
  492. @curseg ends
  493.  
  494. zzlastseg segment
  495.  
  496. zzlastseg ends
  497.  
  498. end start_
  499.  
  500.