News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Search Replace String in a file

Started by ragdog, April 03, 2011, 06:59:12 AM

Previous topic - Next topic

hutch--

 :bg

It would seem the problem is memory allocation if you are having hassles with VirtualAlloc() and while Windows has a variety of memory allocation strategies, the old, antique, deprecated and equally fast reliable and hassle free GlobalAlloc() does the job in this context fine.


    invoke GlobalAlloc,GMEM_FIXED or GMEM_ZEROINIT,buffersize
    mov pMem, eax

  ; rock 'n roll here

    invoke GlobalFree, pMem


Now of course you can do it the hard way, piss around with all of the messy options but if you want it to be clean, simple, fast and reliable, have a look at GlobalAlloc.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

MichaelW

#16
ragdog,

I posted a first attempt at a self-expanding buffer here:

http://www.masm32.com/board/index.php?topic=16378.msg135557#msg135557

eschew obfuscation

donkey

Quote from: hutch-- on April 04, 2011, 12:39:08 AM
:bg

It would seem the problem is memory allocation if you are having hassles with VirtualAlloc() and while Windows has a variety of memory allocation strategies, the old, antique, deprecated and equally fast reliable and hassle free GlobalAlloc() does the job in this context fine.


    invoke GlobalAlloc,GMEM_FIXED or GMEM_ZEROINIT,buffersize
    mov pMem, eax

  ; rock 'n roll here

    invoke GlobalFree, pMem


Now of course you can do it the hard way, piss around with all of the messy options but if you want it to be clean, simple, fast and reliable, have a look at GlobalAlloc.

It wasn't so much what was easiest, from what I understood the problem was that he had to know the size of the destination buffer before he executed the Replace function. The extra overhead in searching out each instance and calculating the extra memory that would be needed seemed to me to be more than the overhead involved in creating a self expanding buffer. GlobalAlloc and the other allocation schemes are not really capable of self expanding efficiently while VirtualAlloc makes it rather easy to do. For "the hard way", VirtualAlloc is just as easy to use as any other allocation scheme.

Nice Michael,

Never thought of page guards, now I have some of my code to modify :)
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable