Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9185437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:16:30+00:00 2026-06-17T19:16:30+00:00

I am doing a project on dynamic memory management. I run into a confuse

  • 0

I am doing a project on dynamic memory management. I run into a confuse about the HeapCreate and HeapAlloc functions.

For the HeapCreate() function, we can create a heap and the function will return a HANDLE. We can initialize the size of heap.

Let’s say winHandle = HeapCreate( 0, 2 * 1024, 0);

Then, I can the HeapAlloc function to allocate on this heap. But I am confuse about the size of the heap. I try an example, I call the HeapAlloc( winHandle, 0, 1024) twice on this heap, so the total will be 2 * 1024. But I can still call the HeapAlloc many times without run into an error.

Let’s say I call the HeapAlloc( winHandle, 0, 1024) three times. The total size of allocation will be 3 * 1024. It is larger than the heap size 2 * 1024. But no error.

Can anyone help me to answer this question?

Thanks,

Here is test code.

// create heap, and return a headle(id) for that heap
HANDLE winHandle = HeapCreate( 0, sizeof(Dog), sizeof(Dog) );


// allocate the heap header to that handle 
void* s = HeapAlloc( winHandle, 0, sizeof(Dog) );   
// check if the alloc is success or not
assert( 0 != s );
printf("%p \n", s);
// load the heap header data
Dog* heapHeader = new(s) Dog( 1, 2, 4);


// allocate the heap header to that handle 
void* ss = HeapAlloc( winHandle, 0, sizeof(Dog) );
// check if the alloc is success or not
assert( 0 != ss );
printf("%p \n", ss);
// load the heap header data
Dog* heapHeadder = new(ss) Dog( 1, 2, 4);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:16:32+00:00Added an answer on June 17, 2026 at 7:16 pm

    Your use of the API is slightly off:

    HANDLE WINAPI HeapCreate(
        DWORD flOptions,
        SIZE_T dwInitialSize,
        SIZE_T dwMaximumSize );
    

    Note that the second parameter to this call is the heap’s initial size, not its maximum size. When you specify 0 for the maximum size, Windows will try to commit new memory pages for the heap once you’ve exhausted the initial pool.

    EDIT

    Note that Windows will round the maximum size given up to the nearest multiple of the system page size. So the actual size of the heap may be more than you requested. In addition, the heap will use some of this memory for its own internal book-keeping. So you won’t be able to make single allocations equal to the size of the heap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am about to create a menu for a project of mine, and I
I am doing project in ASP.Net, and i have used QueryString for dynamic profiles
Currently i am doing the project in RAD i.e. dynamic web project but now
I'm doing a style.php CSS file so I can use some dynamic variables in
I am doing a project which includes dynamic controls creation and removal from the
In Eclipse, the folder structure when I create a Dynamic Web Project is [srikanth@hana
I saw a project, in which they are doing a Dynamic build script in
i am doing a Prolog project and below is my code. :- dynamic yes/1,no/1.
As part of a C programming project I'm doing, I've needed to create my
Project: To create dynamic multi page form that populates the fields in different ways

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.