home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / MAXONC3_6OF8.DMS / in.adf / LIBSRC.LHA / LIBSRC / realloc.asm < prev    next >
Encoding:
Assembly Source File  |  1994-12-03  |  1.1 KB  |  53 lines

  1.  
  2. * Himpelsoft/Maxon C++ Projekt
  3. *
  4. * Library-Modul "realloc"
  5. *
  6. * Jens Gelhar 28.01.92, 01.09.93, 03.12.94
  7.  
  8.     xdef    _realloc,realloc__PvUi
  9.  
  10.     xref    exit__i,_errno,FreeStore__HashTable
  11.     xref    malloc__Ui,free__Pv
  12.  
  13. _realloc:
  14. realloc__PvUi:    ; Stack-Parameter: Zeiger + uint
  15.     move.l    d0,a1
  16.     move.l    8(a7),d1    ; neue Größe
  17.     addq.l    #8,d1        ; 8 Byte Overhead
  18.     cmp.w    #0,a1
  19.     beq.b    .null1
  20.     cmp.l    -4(a1),d1    ; bisherige Größe
  21.     beq.b    .OK        ; identisch
  22. .null1    ; ganz neuen Speicher allozieren:
  23.     move.l    8(a7),-(a7)    ; neue Größe
  24.     jsr    malloc__Ui
  25.     addq.l    #4,a7
  26.     tst.l    d0
  27.     beq.b    .Return
  28.     move.l    d0,a0
  29.     move.l    4(a7),a1
  30.     move.l    8(a7),d1
  31.     move.l    d0,4(a7)    ; Ergebnis merken
  32.     move.l    a1,-(a7)    ; alter Speicher: schon für "free" pushen
  33.     cmp.w    #0,a1
  34.     beq.b    .copOK
  35.     move.l    -4(a1),d0
  36.     subq.l    #8,d0
  37.     bls.b    .copOK
  38.     cmp.l    d1,d0
  39.     bls.b    .copy
  40.     move.l    d1,d0
  41. .copy    move.w    (a1)+,(a0)+    ; wortweises Kopieren ist OK, denn Exec reserviert
  42.     subq.l    #2,d0        ; sowieso nur Blöcke gerader Größe (sogar durch 8 teilbar)
  43.     bne.b    .copy
  44. .copOK    tst.l    (a7)
  45.     beq.b    .null2
  46.     jsr    free__Pv
  47. .null2    addq.l    #4,a7
  48. .OK    move.l    4(a7),d0
  49. .Return    rts
  50.  
  51.     end
  52.  
  53.