News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

GlobalAlloc question...

Started by K_F, February 18, 2014, 08:08:13 PM

Previous topic - Next topic

K_F

Would anyone know if I use the GlobalAlloc/GlobalFree functions extensively.. would it create problems in Windoze ?

I'm thinking of using it to reassign buffer space to changing size requirements.
Essentially I'd always delete the current buffer, before applying for a new one, so this would be an expanding buffer problem.
I'd be using a few buffers..
Was wondering if the OS uses something similar to a heap cleanup.

Another way of doing things is to apply for a very much larger space, and only reapply if the new buff size is greater than the current.
:idea:
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

dedndave

MSDN seems to be trying to steer programmers away from using GlobalAlloc
well - there are some cases where it's still the way to go, like clipboard or some streaming stuff

maybe this will be helpful

http://msdn.microsoft.com/en-us/library/windows/desktop/aa366533%28v=vs.85%29.aspx

i have an app that uses a potentially large amount of memory
i am working on code to use memory-mapped files - i think it's the best solution in my situation
each case is different, though   :P

http://msdn.microsoft.com/en-us/library/windows/desktop/aa366556%28v=vs.85%29.aspx

hutch--

Van,

The GlobalAlloc family of functions call the same procedures that most of the other do at a lower level so the restriction is academic, its fast, can allocate any amount of available memory and its easy to use. The older MOVABLE flags are effectively redundant and only useful for a few specialised backwards compatibility functions like the clipboard. In normal use the GMEM_FIXED flag is the one to use and you have the option of zero initialising the memory as well. You can realloc both up and down in size but for size increase where the same address cannot be used by the OS, you then specify the MOVABLE flag. If the memory was originally allocated with the FIXED flag you just get a pointer back like you did with the GMEM_FIXED flag.

K_F

Thanks dudes.. I vaguely remember (must be the red aviation juice) that the heap get's into a mess with GlobalAlloc... ?
Maybe I'm wrong.. but just was worried that it would bomb, if used too much...

I think I'll have to write a little mem handler, just to make sure
:t

'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

hutch--

Van,

The thing you must watch with any memory allocation strategy is making large numbers of small allocations that are being repeatedly allocated and deallocated as you end up with memory fragmentation. Allocating a single large block and chopping it up yourself is much faster and free of memory fragmentation.

K_F

Ja.. that's what I thought I'd eventually be doing
:t
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

dedndave

that was one of the things that lead me to file mapping
the size of the file(s) can grow to be large, while the "view" memory remains constant size