项目不让用malloc,今天闲来无事突然想到如何才能得到malloc空间的问题?
——这不是很傻吗?malloc用于user自行临时在堆中创建一块使用内存。内存会说,你自己创建的你自己去查代码,要不就问问你的屁屁:)
不管怎么样,还是有这样的API提供的,蛮有趣的:)
_msize
Description:
Return the size of a memory block allocated in the heap
size_t _msize(void *memblock);
Param: memblock
Pointer to the memory block
Return Value:
_msize returns the size(in bytes) as an unsigned integer
Head files:
malloc.h
Example:
void * pointer = malloc(sizeof(int));
unsigned int msize= 0;
msize = _msize(pointer);
free(pointer); //it is important
pointer = NULL: