home *** CD-ROM | disk | FTP | other *** search
/ Groovy Bytes: Behind the Moon / groovybytes.iso / GROOVY / SND_TOOL / FUNK108A.ZIP / DOS32V30.ZIP / PAL / MALLOC / REALLOC.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-05-20  |  1.5 KB  |  60 lines

  1. ;****************************************************************************
  2. ; Filename: REALLOC.ASM
  3. ;   Author: Peter Andersson
  4. ;  Version: 0.3
  5. ;  Created: 1995.03.12
  6. ;  Updated: -
  7. ;****************************************************************************
  8. ; Copyright 1994, Peter Andersson.
  9. ; All rights reserved.
  10. ;****************************************************************************
  11. ; Function: PVOID @realloc(PVOID ptr,ULONG size)
  12. ;  Comment: Resizes a previously allocated block. If the block pointer is NULL
  13. ;           a new block will be allocated and if the block size if zero then
  14. ;           it will free the block.
  15. ;    Input: Eax - memory block to resize
  16. ;           Edx - new size of the block
  17. ;  Returns: Pointer to the resized memory block (except when freeing when it
  18. ;           returns a NULL(0) pointer) or 0 if it failed.
  19. ;****************************************************************************
  20.  
  21.     Include    STDDEF.INC
  22.     Include    "MEMORY.INC"
  23.  
  24.     Codeseg
  25.  
  26. Proc    realloc ,2
  27.         TestZ    Edx
  28.         Jz    @@FreeBlk
  29.         Cmp    [Eax-Size AllocBlock+AllocBlock.Ident],ALLOCID
  30.         Jne    @@Exit01
  31.         TestZ    Eax
  32.         Jz    @@AllocBlk
  33.         Push    Eax,Edx
  34.         Call    @resize
  35.         TestZ    Eax
  36.         Jz    @@MoveBlk
  37.         Add    Esp,8
  38.         Ret
  39.     Align    4
  40. @@FreeBlk:    Call    @free
  41. @@Exit01:    Clear    Eax
  42. @@Exit02:    Ret
  43.     Align    4
  44. @@AllocBlk:    Mov    Eax,Edx
  45.         Call    @malloc
  46.         Ret
  47.     Align    4
  48. @@MoveBlk:    Mov    Eax,[Esp]
  49.         Call    @malloc
  50.         TestZ    Eax
  51.         Jz    @@Exit02
  52.         Mov    Edx,[Esp+4]
  53.         Mov    Ecx,[Esp]
  54.         Add    esp,8
  55.         Call    @memcpy
  56.         Ret
  57. Endp
  58.  
  59.     End
  60.