News:

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

Misc: RtlMoveMemory, rep lods, HeapAlloc limits

Started by jj2007, February 12, 2008, 03:47:21 PM

Previous topic - Next topic

jj2007

A few questions that plagued me today:

1. invoke RtlMoveMemory, pBuffer, pHeapCt, NumBytes: strangely enough, this API creates Unicode in the destination. It copies the correct no. of bytes but in the destination I see only UC, i.e. half of the text is lacking... is that a known issue? I used this in a EM_STREAMOUT callback. After I switched to good old rep movsd, the result was fine.

2. HeapAlloc: I read in the forum that the limit is around 4 Mega. I tested this and had no problems up to 1.5 Giga. Is there a documented answer to this?

3. rep lods: Opcodes.hlp says "Use with REP prefixes". Is there any known use for loading a thousand chars into the accumulator?

Thanks for enlightening me  :bg 

ecube

If half of the text is lacking with rtlmovememory then perhaps you did something wrong with either the type of data you're inputing or the way you're reading the results. I'm not saying this in a negative way just i've used rtlzmovememory extensively and any issue I had was always due to my own faults. Globalalloc is pretty dangerous I remember I set the memory to moveable and it kept copying an entire different memory buffs contents into it's own, even though I never targeted that memory, i'll have to reproduce the code to show you what I mean. Also f0dder claims globalalloc just calls heapalloc eventually on nt+ anyway so it's better to use heapalloc as microsoft recommends it aswell. globalalloc is so ancient anyway.

MichaelW

For EM_STREAMOUT what value are you passing in wParam?

http://msdn2.microsoft.com/en-us/library/bb774304.aspx

From the February 2003 PSDK:
Quote
Windows Me/98/95: The heap managers are designed for memory blocks smaller than four megabytes. If you expect your memory blocks to be larger than one or two megabytes, you can avoid significant performance degradation by using the VirtualAlloc or VirtualAllocEx function instead.

In the current MSDN documentation this information has disappeared:

http://msdn2.microsoft.com/en-us/library/aa366597.aspx

QuoteIs there any known use for loading a thousand chars into the accumulator?

I can't think of any, but if there were in my tests a mov loop was faster.

eschew obfuscation

jj2007

Hi Michael,

For the EM_STREAMOUT, I pass SF_TEXT - nothing mysterious here.
I had this Unicode problem on my office PC (XP SP2), but now I am at home (SP1), and it behaves correctly. I swear it was Unicode - I looked at it with a HEX editor and saw all the nice 00 41 00 42 etc in front of me. And the problem disappeared in the moment when I switched to good ol' rep movsd. Strange.

Re HeapAlloc, it just tickled me to test the limits, and they seem to be over 1 Giga now.

invoke HeapAlloc, eax, HEAP_GENERATE_EXCEPTIONS, 1200000000 ;nBytes

That doesn't choke! Here on my SP1 box the limit is near, but my SP2 box in office goes until 1.5 Giga. Not that I really need it  :green

xmetal

Quote from: jj2007 on February 12, 2008, 03:47:21 PM
3. rep lods: Opcodes.hlp says "Use with REP prefixes". Is there any known use for loading a thousand chars into the accumulator?

I remember reading about this in some post in the old MASM forum. It is a used to cache a small amount of contiguous memory that is just about to be processed in a loop or something.