The MASM Forum Archive 2004 to 2012

General Forums => The Laboratory => Topic started by: denise_amiga on June 02, 2005, 03:53:14 PM

Title: question: is this correct?
Post by: denise_amiga on June 02, 2005, 03:53:14 PM


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    szDup   proto :DWORD

.data
tststr  db "This is a test!!",0

.code

start:

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    call main

    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    LOCAL txtbuffer :dword

    mov     txtbuffer, rv(szDup, addr tststr)

    invoke  szUpper, txtbuffer

    print   offset tststr,13,10
    print   txtbuffer,13,10

    free    txtbuffer           ; macro

    mov   eax,input(13,10,"Press enter to exit...")

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

align 4

szDup proc src:DWORD

    push    esi
    mov     esi, [esp+2*4]
    test    esi, esi
    jz      @error                                          ; no str

    invoke  szLen, esi
    add     eax, 1                                          ; +0 terminator
    invoke  GlobalAlloc, GMEM_FIXED or GMEM_ZEROINIT, eax
    push    eax                                             ; store ptr
    test    eax, eax
    jz      @error                                          ; no memory

    invoke  szCopy, esi, eax                                ; dupping
    pop     eax                                             ; restore ptr
    pop     esi

    ret     1*4

@error:
    xor     eax, eax
    pop     esi

    ret     1*4

szDup endp

OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start

Title: Re: question: is this correct?
Post by: hutch-- on June 03, 2005, 02:39:41 AM
denise,

It looks fine, should work OK and deallocates the memory correctly.
Title: Re: question: is this correct?
Post by: denise_amiga on June 03, 2005, 02:49:59 PM
another question, hutch--

is necessary, for each use of the function, in this case szDup, to release the memory, or simply once when finishing?

example:



...
LOCAL ptrbuffer:DWORD
...
...
mov ptrbuffer,rv(szDup, addr txt1)
...
...
; is necesary free memory, for reuse ptrbuffer?
mov ptrbuffer,rv(szDup, addr txt2)
...
...
; is necesary free memory, for reuse ptrbuffer?
mov ptrbuffer,rv(szDup, addr txt3)
...
...
free ptrbuffer
ret

Title: Re: question: is this correct?
Post by: denise_amiga on June 04, 2005, 06:40:33 AM
sorry for stupid question...



repeat 10000000
  mov ptrbuffer,rv(szDup, addr txt1)
  ;free(ptrbuffer)
endm



with free commented, the program consumes too much memory

Title: Re: question: is this correct?
Post by: hutch-- on June 04, 2005, 07:00:40 AM
Denise,

With a single DWORD variable, just overwrite it with your new value.

The 10 million repeats of a single line of code is still a very large block of code so it is likely to lock up either MASM or if you can get it to build at all, the OS.
Title: Re: question: is this correct?
Post by: denise_amiga on June 04, 2005, 07:32:35 AM
I understand to you, hutch--, the test repeat/endm was only to verify the memory that the program uses, does not to see the size of the program, I feel if I was not explained me with clarity. :red