How to check the memory allocated using malloc function.
How to check the memory allocated to mem.Code:int *mem; mem=(int *)malloc(sizeof(int));
This is a discussion on Memory allocation within the C Programming forums, part of the General Programming Boards category; How to check the memory allocated using malloc function. Code: int *mem; mem=(int *)malloc(sizeof(int)); How to check the memory allocated ...
How to check the memory allocated using malloc function.
How to check the memory allocated to mem.Code:int *mem; mem=(int *)malloc(sizeof(int));
The size you mean? There's no portable way to do that. Each library implementation is free to add a function to get the size, but is not required to.
Better to keep check of the size manually.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
How to check it manually?
Just do it theoretically, int is 4 bytes. The rest is easy.
The actual size is not guaranteed to be "just" 4 bytes. It may be more. But as I mentioned, there's no "100% guaranteed" way to check it. It differs from each implementation.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
What exactly do you want to "check"? There are only two valid return values from malloc(): NULL for a failed allocation, and a valid pointer to a block of the size you requested, which is ANY other value than NULL. [Assuming of course we are talking about a malloc() that is implemented by a normal system library, rather than "I built my own malloc function, and I want to check if it works"].
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.