News:

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

sizeof

Started by Astro, July 27, 2009, 04:58:43 PM

Previous topic - Next topic

Astro

Quote from: dedndave on July 28, 2009, 03:52:42 AM
QuoteHowever you allocate the buffer, the first dword must be set to 5.
huh ?   :eek
+1

DWORD = 4 bytes. Why set the value to 5 bytes?

The length that wants setting before the call will be cloesr to 4 + 100 = 104. If I set it to 5, it will error every time (ERROR_INVALID_USER_BUFFER). Once I've ran it, I'll have a better idea of the size I want.

I know the fisrt DWORD of the memory block must be set to the size of the structure as this is where the function will be expecting to see cbSize.

@dedndave: By allocating a seperate heap, I can set the heap to be able to grow, not be executable, etc... If I don't do this, the default heap might not be expandable, and might be executable. It might also reduce my chance of breaking something.  :cheekygreen:

The article talks of "system overhead" for the heap but fails to say what this is.  ::)

Best regards,
Astro.

MichaelW

The attachment contains a minimal C test app compiled with Visual C++ Toolkit 2003 that shows what I am describing. API structures where the last member is the first character of a variable-length string are fairly common. Searching my 2003 version of the PSDK for "ANYSIZE_ARRAY" I find a total of 12. AFAIK the intention is that instead of allocating a structure you allocate a buffer of an appropriate length, cast the buffer pointer to a structure pointer, and then access the structure members by name through the pointer.

[attachment deleted by admin]
eschew obfuscation

Astro

Hi Michael,

Not forgotton - just working on something else ATM.  :U

Best regards,
Astro.