64,281
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 分配内存
/// </summary>
void *Alloc(size_t _NumBytes)
{
void *ptr = (void *)0x1000;
size_t size = 0x1000;
if (_NumBytes >= size)
{
return NULL; //不足以分配所请求的大小
//因为要留位置记录分配块的大小, 所以_NumBytes == size也不行
}
void *ptr_alloc;
//continue allocating
//这里怎么编写?
return ptr_alloc;
}
/// <summary>
/// 分配内存
/// </summary>
void *Alloc(size_t _NumBytes)
{
static char * pOffset = (char*)ptr; //记录内存分配后,下次再分配的开始位置。
void *ptr = (void *)0x1000;
size_t size = 0x1000;
if (_NumBytes+pOffset >= size)
{
return NULL; //不足以分配所请求的大小
//因为要留位置记录分配块的大小, 所以_NumBytes == size也不行
}
void *ptr_alloc;
//continue allocating
//这里怎么编写?
ptr_alloc = (void*)pOffset;
pOffset += _NumBytes; //下次分配就从pOffset这里开始。
return ptr_alloc;
}