Void and malloc( )
Feb 28, 2011 at 12:37am UTC
I have the following code segment:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
void *Cell_alloc;
int Alloc_cell( void **Allocator, int Sizeof_element, int Element_count )
{
if ( ( Allocator = ( void * )calloc( Element_count, Sizeof_element ) ) == NULL )
{
return 0;
}
return 1;
}
Alloc_cell( Cell_alloc, sizeof ( int ), 2 );
//...other code...
free( Cell_alloc );
Now my question. When I free
Cell_alloc , will it free all the memory allocated by it with
free( ) ? I've tried googling it but found nothing of use.
Last edited on Feb 28, 2011 at 1:23am UTC
Feb 28, 2011 at 12:57am UTC
Where do you actually point Cell_alloc at memory that was allocated?If you take the pointer returned by calloc and have Cell_alloc point to it, then yes, it will be freed.
Feb 28, 2011 at 1:22am UTC
My mistake. This was just an example code I wrote. I've changed the code.
Topic archived. No new replies allowed.