| Thread overview | |||||
|---|---|---|---|---|---|
|
January 03, 2011 GC works with malloc() works, but throws out of memory with HeapAlloc(). Why? | ||||
|---|---|---|---|---|
| ||||
Hi, I've recompiled the code for my library to redirect all calls to malloc(), free(), realloc(), and calloc() to HeapAlloc(), HeapFree(), and HeapReAlloc(). The problem? It doesn't work -- it throws OutOfMemory when the program is starting (in the mallocNoSync() function) even though those functions do not fail (I've checked the return values of the functions, and they don't fail; I've also told them to throw exceptions on failure, and none is thrown). The funny thing is, if I redirect DMD's malloc() to the msvcrt.dll malloc(), it works perfectly fine, so it's not like it's a library issue. And it doesn't seem to be an alignment issue either. Does anyone have any idea what might cause this? (And I've redirected *all* calls, including the ones from monitor.c and such, so it isn't a problem with one allocator freeing another allocator's memory.) What could possibly be the issue? Any ideas? Thank you! | ||||
January 04, 2011 Re: GC works with malloc() works, but throws out of memory with HeapAlloc(). Why? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to %u | On Tue, 04 Jan 2011 01:12:53 +0200, %u <wfunction@hotmail.com> wrote: > > I've recompiled the code for my library to redirect all calls to malloc(), > free(), realloc(), and calloc() to HeapAlloc(), HeapFree(), and HeapReAlloc(). Sorry, do you mean the libc functions? The GC doesn't use those to allocate its memory pools, and uses page allocation functions (mmap on *nix and VirtualAlloc on Windows). If you mean the GC functions, then wouldn't your hooked malloc be called before mallocNoSync is called? -- Best regards, Vladimir mailto:vladimir@thecybershadow.net | |||
January 04, 2011 Re: GC works with malloc() works, but throws out of memory with HeapAlloc(). Why? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Vladimir Panteleev | > Sorry, do you mean the libc functions? The GC doesn't use those to allocate its memory pools, and uses page allocation functions (mmap on *nix and VirtualAlloc on Windows). If you mean the GC functions, then wouldn't your hooked malloc be called before mallocNoSync is called?
I actually found the error (after > 8 hours of searching); it was because HeapReAlloc wasn't calling HeapAlloc if the passed pointer was null, the way realloc() is supposed to. Thank you for your reply though!
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply