HeapCreate的一个小问题。

firendlys 2011-12-08 04:20:42


HANDLE hp=HeapCreate(0,0,1);
void *p=HeapAlloc(hp,0,2*1024);

if(p)
cout <<"success!"<<endl;




以上代码,为什么能分配成功呢?HeapCreate最后的参数1怎么好像无效了?
...全文
101 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
周晓荣 2011-12-08
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 yisikaipu 的回复:]

引用 1 楼 et214721856 的回复:HeapCreate 的第三个参数表示的是页的数量

就是字节数,不是页的数量,是determines页的数量

这个1随便写写,以区别于0

HeapCreate(0,0,1); // 4k
HeapCreate(0,0,4096); // 4k

HeapCreate(0,0,4097); // 8k
[/Quote]

原来如此~我看错了。

我代表楼主感谢你,哈哈
yisikaipu 2011-12-08
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 et214721856 的回复:]HeapCreate 的第三个参数表示的是页的数量[/Quote]

就是字节数,不是页的数量,是determines页的数量

这个1随便写写,以区别于0

HeapCreate(0,0,1); // 4k
HeapCreate(0,0,4096); // 4k

HeapCreate(0,0,4097); // 8k
周晓荣 2011-12-08
  • 打赏
  • 举报
回复
The HeapCreate function creates a private heap object from which the calling process can allocate memory blocks by using the HeapAlloc function. The initial size determines the number of committed pages that are allocated initially for the heap. The maximum size determines the total number of reserved pages. These pages create a block in the process's virtual address space into which the heap can grow. If requests by HeapAlloc exceed the current size of committed pages, additional pages are automatically committed from this reserved space, if the physical storage is available.

HeapCreate 的第三个参数表示的是页的数量,1页4K,x86/x64都是4k

所以HeapAlloc分配2K的内存就能够成功。
Creating Windows CreateMDIWindow CreateWindow CreateWindowEx RegisterClass RegisterClassEx UnregisterClass Message Processing BroadcastSystemMessage CallNextHookEx CallWindowProc DefFrameProc DefMDIChildProc DefWindowProc DispatchMessage GetMessage GetMessageExtraInfo GetMessagePos GetMessageTime GetQueueStatus InSendMessage PeekMessage PostMessage PostQuitMessage PostThreadMessage RegisterWindowMessage ReplyMessage SendMessage SendMessageCallback SendMessageTimeout SendNotifyMessage SetMessageExtraInfo SetWindowsHookEx TranslateMessage UnhookWindowsHookEx WaitMessage Window Information AnyPopup ChildWindowFromPoint ChildWindowFromPointEx EnableWindow EnumChildWindows EnumPropsEx EnumThreadWindows EnumWindows FindWindow FindWindowEx GetClassInfoEx GetClassLong GetClassName GetClientRect GetDesktopWindow GetFocus GetForegroundWindow GetNextWindow GetParent GetProp GetTopWindow GetWindow GetWindowLong GetWindowRect GetWindowText GetWindowTextLength IsChild IsIconic IsWindow IsWindowEnabled IsWindowUnicode IsWindowVisible IsZoomed RemoveProp SetActiveWindow SetClassLong SetFocus SetForegroundWindow SetParent SetProp SetWindowLong SetWindowText WindowFromPoint Processes and Threads CreateEvent CreateMutex CreateProcess CreateSemaphore CreateThread DeleteCriticalSection DuplicateHandle EnterCriticalSection ExitProcess ExitThread GetCurrentProcess GetCurrentProcessId GetCurrentThread GetCurrentThreadId GetExitCodeProcess GetExitCodeThread GetPriorityClass GetThreadPriority GetWindowThreadProcessId InitializeCriticalSection InterlockedDecrement InterlockedExchange InterlockedIncrement LeaveCriticalSection OpenEvent OpenMutex OpenProcess OpenSemaphore PulseEvent ReleaseMutex ReleaseSemaphore ResetEvent ResumeThread SetEvent SetPr

64,680

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧