The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: drjr on October 05, 2007, 06:07:38 PM

Title: CoGetMalloc function (memory allocation)
Post by: drjr on October 05, 2007, 06:07:38 PM

Hi, for all friends programmers:

This is the problem:   I`m using CoGetMalloc function to allocate 1.600.000 byes in memory, and
this function give me almost 8 times this amount but when I try to fill these byte an error write protection fault occurs. Do someone known the answer ?

                                                                best regards for all

Title: Re: CoGetMalloc function (memory allocation)
Post by: MichaelW on October 05, 2007, 10:15:04 PM
AFAIK the IMalloc Alloc method may allocate more than the requested number of bytes, but 8x seems way out of line. Can you post your code?
Title: Re: CoGetMalloc function (memory allocation)
Post by: Tedd on October 06, 2007, 02:01:27 PM
(Just to make sure :wink) CoGetMalloc gives you a pointer to a memory-allocator object, which you can then call Alloc from its IMalloc interface to do the actual memory allocation. The calls on the object are made using a com-style convention, so plain invoke won't work correctly.
Better post your code :bdg
Title: Re: CoGetMalloc function (memory allocation)
Post by: japheth on October 06, 2007, 04:04:23 PM
Quote from: Tedd on October 06, 2007, 02:01:27 PM
(Just to make sure :wink) CoGetMalloc gives you a pointer to a memory-allocator object, which you can then call Alloc from its IMalloc interface to do the actual memory allocation. The calls on the object are made using a com-style convention, so plain invoke won't work correctly.

Yes. Using CoTaskMemAlloc instead of CoGetMalloc might do what you want, drjr.