(quote)
Code:
int *pointer = (int *) malloc ( 12 );
malloc reserves 12 Bytes on my Heap. I have once heard that malloc always reserves one pagesize. Is this true?
It's my understanding that when using the malloc function, you are ASKING for memory resources, as opposed to "telling" the system. Worried that you wont have enough memory?
When invoking malloc(), it dynamically allocates memory (or trys to), but the function itself also returns a value of NULL if it failed.
Also for portability (maybe that's not a concern here) I would never use a literal in calling malloc; I always feel safer using the sizeof() thingy.
Here's a re-write sample:
Code:
int *pointer = (int *) malloc ( 12 * sizeof(int) ); // Ask for 12 bytes of size int
if ( pointer == NULL) // check if successful
{
puts("Out of HUNK!") // hehehe... remember that one from the old DOS days?
return 1;
}
puts(" You have 12 bytes of type int reserved.\n")
Hope this works for you & good luck!