Sign in to follow this  

Win32 Heaps

This topic is 3112 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been trying to figure out how Win32 heaps work, but I've hit a stumbling block. Here's an example: If I call _get_heap_handle(), I get 0x00270000. However, when I use new or malloc, the address returned has the base page address of 0x00430000. Even when I enumerate through all the heaps (it shows 3), the default Win32 heap is at 0x00550000 and some mystery heap is at 0x001F0000. Nothing seems to match the page addresses returned by new/malloc. Clearly I'm missing something here concerning the CRT heap and where new/malloc allocate from. Are new/malloc using VirtualAlloc , like how dlMalloc works? What would actually use the CRT heap? Thanks for any help! (I'm using VS2005 and compiling for 32-bit)

Share this post


Link to post
Share on other sites
Quote:
Original post by GaryNas
I've been trying to figure out how Win32 heaps work, but I've hit a stumbling block. Here's an example:

If I call _get_heap_handle(), I get 0x00270000. However, when I use new or malloc, the address returned has the base page address of 0x00430000.

Even when I enumerate through all the heaps (it shows 3), the default Win32 heap is at 0x00550000 and some mystery heap is at 0x001F0000. Nothing seems to match the page addresses returned by new/malloc.

Clearly I'm missing something here concerning the CRT heap and where new/malloc allocate from. Are new/malloc using VirtualAlloc , like how dlMalloc works? What would actually use the CRT heap?

Thanks for any help!

(I'm using VS2005 and compiling for 32-bit)


The heap handle points to the data structure that describes the heap. That structure need not be contiguous with the actual heap memory (aka the addresses dispensed through that handle). The heap data structure is likely a circular linked list storing pointers that point to the memory dispensed through the various heap functions. A crude real world analogy of this set up would be the difference between a phone book and the entire local phone system. A phone book is a list of all the phone numbers, it's not the actual switches activated when a number is dialed. In this analogy, the phone book is the heap handle and the dispensed addresses are the entire local phone system.

Don't forget HeapAlloc and related functions. [grin]

Have you read this old school doc? Managing Heap Memory in Win32

It doesn't get into that detail, but it's worth checking out if you've never checked it out before.



Share this post


Link to post
Share on other sites

This topic is 3112 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this