这是一段对灰度图二值化的程序,不太了解分配内存的的问题,求注解
BYTE *temp;
BYTE *start;
start = gdata;
temp = (BYTE*)GlobalAllocPtr(GMEM_MOVEABLE, w*h);
memcpy(temp,start,w*h);

int i,j;
int hist[256];
for(i=0;i<256;i++)
hist[i]=0;
for(i=0;i<h;i++)
for(j=0;j<w;j++)
{
hist[temp[i*w+j]]++;
}

for(i=0;i<2*h/3;i++)
for(j=0;j<w;j++)
{
if(temp[i*w+j]>50)
temp[i*w+j]=255;
else
temp[i*w+j]=0;
}
memcpy(start,temp,w*h);
pDC = GetDC();
Showg(w,h,gdata,pDC);

解决方案 »

  1.   

    temp = (BYTE*)GlobalAllocPtr(GMEM_MOVEABLE, w*h);
    LZ问的是这个吗?
    MSDN的相关说明:
    Allocates movable memory. Memory blocks are never moved in physical memory, but they can be moved within the default heap. The return value is a handle to the memory object. To translate the handle into a pointer, use the GlobalLock function.This value cannot be combined with GMEM_FIXED.供LZ参考的文章:
    http://student.csdn.net/space.php?uid=7883&do=blog&id=10544