I am using LocalAlloc to allocate memory for the file. I read a post a long time ago that said "if you know the size of the file you can use a dedicated buffer for the file". But i can't find it again.

Instead of calling LocalAlloc like i did below how would i do this by using a buffer.

The files are very small. The size is usually 300 bytes but never more than 600 bytes. Could someone tranlate this for me...It seem simple but i can't figure it out. An solution will answer a lot of questions about allocation . . .

Thank You in Advance...


.data?

GetMFile1 DWORD ?
Package1 DWORD ?

.code

invoke LocalAlloc, GMEM_FIXED, GetMFile1
mov Package1, eax
mov eax, GetMFile1
Posted on 2002-03-01 22:16:41 by cmax
maybe:

LOCAL Buffer[1024]:BYTE
Posted on 2002-03-01 22:20:54 by JimmyClif


.DATA

buffer1 DB 300 DUP(0)
buffer2 DB 600 DUP(0)

.code

invoke ReadFile, HandleToTheFile, OFFSET buffer[color=blue][b]X[/b][/color]...


Hows' that? :)
Posted on 2002-03-01 22:23:14 by stryker
So when you call LocalAlloc it is basiclly a ReadFile.
Can I invoke my own Buffer.


MY_Alloc Proc :DWORD, :DWORD
MY_GMEM db 1024


invoke MY_Alloc , MY_GMEM , GetMFile1
mov Package1, eax
mov eax, GetMFile1
Posted on 2002-03-01 22:43:00 by cmax
Nope, Local Alloc is used for dynamic memory allocation. ReadFile is used for reading files. My example up there is a direct way of using a buffer from the data section.


If you don't know the size of the buffer, use a memory allocation function such as LocalAlloc, GlobalAlloc, HeapAlloc, VirtualAlloc, since you said you know the size of the file, just declare the buffer on the data section. :)
Posted on 2002-03-01 22:46:22 by stryker
But in your example you write 300+600 "0"'s into the exe,
mine doesn't and has the same result.
Posted on 2002-03-01 22:50:28 by JimmyClif
No, you choose either buffer1 or buffer2, you can't have both. :) Either way, same thing, mine is global, yours is local. Choose your flavor(Sounds like an Ice Cream Parlor :grin: ).




.data?
buffer1 DB 300 DUP(?)
buffer2 DB 600 DUP(?)
Posted on 2002-03-01 22:52:39 by stryker
LOL ;)
Posted on 2002-03-01 23:01:26 by JimmyClif
dynamic memory allocation is what i really mean...I want to read with in the memory using my own buffer. I used the wrong word file... Can you use your own buffer for doing something like that and avoid using LocalAlloc somehow...

I like that ReadFile idea. I going to try it both ways..

By the way umberg6007, I got the Arrays thing you answer my post about down packed. Now i think i got my data lined up properly. And on top of that i can really see what i am doing to the very last byte. But it a hard desision to know which is as fast as the other. I'm thinking if you work with an lot of byte data to use the Byte style to keep confussion down: as far a effecicy and speed would they both prove to be the same...(?)Posted on 2002-03-01 23:04:30 by cmax
As far as I know there are only 2 ways to determine the size of a buffer.

1. Use a memory allocation function such as LocalAlloc. When you succesfully use LocalAlloc, it will return to you the address in memory that was allocated(this is in EAX). You can then use the value of EAX like this: invoke ReadFile, HandleToTheFile, eax ...

2. The same idea I presented earlier. This is not dynamic, This is static. Static I mean is that the size of the buffer is already determined like buffer DB 300 DUP(?). This has a buffer size of 300 bytes, if the file you're going to read is greater than 300 bytes then you're in trouble. If it's less than, then that's OK!

By the way umberg6007, I got the Arrays thing you answer my post about down packed. Now i think i got my data lined up properly. And on top of that i can really see what i am doing to the very last byte.


Nice :alright:


the 2nd one Buffer1 DB 60 DUP(?) Actually it looks the same, but it's better to use the 2nd one. It's more explicitly saying your using it as a byte(strings). using DD would likely to say your doing this for something else.
Posted on 2002-03-01 23:14:41 by stryker
Thank both of you guys very much for the rapit reponse.
Now i got some darn good ideas to work with.
Back to the
Posted on 2002-03-01 23:30:14 by cmax