Hey folks,

I'm writing a DLL for bitmap manipulation. Therefor I use GetDIBits and SetDIBits. The problem is, that a big bitmap may not fit in my string when I declare it like "szStr db 5760000d ?". Everything bigger than 1600x1200x24 won't fit in there! At runtime I know the size of the bitmap. I guess I will need to use the Heap functions. But since I'm new to assembler and never had to manage my memory by myself, I would appreciate a specific example.

Thank you!

So long,
yaXay
Posted on 2003-10-23 17:28:07 by yaXay
yaXay,

For what you require, you are ar better off to dynamically allocate the memory you require for a bitmap. You can use an old function like GlobalAlloc() with no problems at all and if you allocate it as fixed memory, the return value is thew address to write to so its very easy to use.

There3 are of course other allocation functions available as well so basically just pick what will do the job for you.

Regards,
http://www.asmcommunity.net/board/cryptmail.php?tauntspiders=in.your.face@nomail.for.you&id=2f46ed9f24413347f14439b64bdc03fd
Posted on 2003-10-23 17:53:19 by hutch--
Hey hutch,

thanx for your fast reply, but the msdn told me, that the Global and Local Functions are slow. I wouldn't write my stuff in asm, when I would not try to get as much speed as possible. But all those functions confuse me a lot. As far as I understood the msdn my steps should be the following:
1. Create a heap object (HeapCreate)
2. Allocate memory (HeapAlloc)
3. Use the memory (mov pointer, eax -> use like this: mov , "Some String!")
4. Free memory (HeapFree)
5. Destroy heap object (HeapDestroy)

Is that correct??

Or would you use GetProcessHeap? Might be even faster.. what do you think??
What about locking? I don't need that, do I?

Thanks so far,
yaXay
Posted on 2003-10-23 20:33:55 by yaXay

Hey hutch,

thanx for your fast reply, but the msdn told me, that the Global and Local Functions are slow. I wouldn't write my stuff in asm, when I would not try to get as much speed as possible. But all those functions confuse me a lot. As far as I understood the msdn my steps should be the following:
1. Create a heap object (HeapCreate)
2. Allocate memory (HeapAlloc)
3. Use the memory (mov pointer, eax -> use like this: mov , "Some String!")
4. Free memory (HeapFree)
5. Destroy heap object (HeapDestroy)

Is that correct??

Or would you use GetProcessHeap? Might be even faster.. what do you think??
What about locking? I don't need that, do I?

Thanks so far,
yaXay


They aren't that slow unless you're doing a lot of mallocs and frees all the time.
For occasional use, it's going to be faster than trying to simulate these routines yourself.
Cheers,
Randy Hyde
Posted on 2003-10-23 23:51:17 by rhyde


mov [filesize],SIZE_OF_YOUR_BITMAP
invoke GetProcessHeap
mov [hheap],eax
invoke HeapAlloc,eax,HEAP_ZERO_MEMORY,[filesize]
mov [your_buf],eax
; ... work with it ...
; ... and then clean it ...
clean_up:
api HeapFree,[hheap],0,[your_buf]


You can use VirtualAlloc. But avoid using GlobalAlloc because there are several problems with it, well documented on this forum. :)
Posted on 2003-10-24 03:24:34 by pelaillo
yaXay,

The problems with GlobalAlloc() are basically that it is not flexible enough for many of the uses in Windows coding but to allocate a single block of memory, it has no problems at all. On benchmarking, it is no slower than most of the others so speed is not your problem here. It is easier to use with a fixed location as follows.


invoke GlobalAlloc,GMEM_FIXED,Your_Size
mov lpMem, eax

Most of the other flags for this API are superceded by other memory functions so you do have a choice if youy need other things like fast allocate and deallocate or cross application scope.

Once memory is allocated, it memory and there is no difference in speed whatsoever.

The problem with trying to build this size in the .DATA section is that it will make your EXE file that much larger for no advantage.

Regards,
http://www.asmcommunity.net/board/cryptmail.php?tauntspiders=in.your.face@nomail.for.you&id=2f46ed9f24413347f14439b64bdc03fd
Posted on 2003-10-24 06:17:42 by hutch--