什么叫做 自建堆?怎么使用呢。

ajp2002 2004-09-17 09:37:48
static HANDLE s_hHeap;
void* p =::HeapAlloc(s_hHeap, HEAP_ZERO_MEMORY, size);

s_hHeap是个什么样的概念
...全文
494 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
DentistryDoctor 2004-09-17
  • 打赏
  • 举报
回复
请阅读<Windows核心编程>CH-18
DentistryDoctor 2004-09-17
  • 打赏
  • 举报
回复
The HeapAlloc function allocates a block of memory from a heap. The allocated memory is not movable.
一般来说HeapAlloc是从进程的默认堆栈中分配内存的,GetProcessHeap可以得到此堆的句柄。
HeapCreate用于自己创建辅助堆栈。
shakaCY 2004-09-17
  • 打赏
  • 举报
回复
自己开辟的一块内存区域,并具有自己知道的句柄(如s_hHeap)对它进行控制!
snaill 2004-09-17
  • 打赏
  • 举报
回复
Memory allocated by HeapAlloc is not movable. The address returned by HeapAlloc is valid until the memory block is freed or reallocated; the memory block does not need to be locked. Because the system cannot compact a private heap, it can become fragmented.

Applications that allocate large amounts of memory in various allocation sizes can use the low-fragmentation heap to reduce heap fragmentation.

Serialization ensures mutual exclusion when two or more threads attempt to simultaneously allocate or free blocks from the same heap. There is a small performance cost to serialization, but it must be used whenever multiple threads allocate and free memory from the same heap. Setting the HEAP_NO_SERIALIZE value eliminates mutual exclusion on the heap. Without serialization, two or more threads that use the same heap handle might attempt to allocate or free memory simultaneously, likely causing corruption in the heap. The HEAP_NO_SERIALIZE value can, therefore, be safely used only in the following situations:



The process has only one thread.
The process has multiple threads, but only one thread calls the heap functions for a specific heap.
The process has multiple threads, and the application provides its own mechanism for mutual exclusion to a specific heap.
门吹西风 2004-09-17
  • 打赏
  • 举报
回复
堆就是一块内存啊.
ajp2002 2004-09-17
  • 打赏
  • 举报
回复
to : DentistryDoctor(牙科医生)
你并没回答我的问题啊,怎么使用这个句柄控制自建堆呢
to: shakaCY(天舞宝轮) ( )
你并没回答我的问题啊,怎么使用这个句柄控制自建堆呢

谢谢,再现等候答案
chen18s 2004-09-17
  • 打赏
  • 举报
回复
堆栈和栈是相等的,堆是另外的
栈是程序启动时系统自动分配的固定内存块
而堆是临时分配的一块动态内存,比如new 和delete就在堆中完成
自建堆,就是自己建的堆咯!
呵呵

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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