Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

free() question

Status
Not open for further replies.

DoraC

Programmer
May 7, 2002
98
US
Hi,

I am requesting arrays of free-store memory as follows:
Code:
ppvMemoryBlock =
( void** )calloc( iSize
                 ,sizeof( void* ) );

am referencing it (after allocating the
constituent void* values) as follows:
Code:
myFunction( *(ppvMemoryBlock + iArrayCounter) );
Both of which work fine. But,
Code:
free( ppvInMemoryBlock + iArrayCounter );
fails. Shouldn't I be able to free individual units of memory returned as a group by calloc, as I'm trying to do here?

Thanks!
dora c
 
That depends, is the change from
ppvMemoryBlock
to
ppvInMemoryBlock

just a typo when you posted, or is it really that in your code?

--
 
That's really in my code... they're actually different variables but point to the same address.

Sorry about that - I was trying to slice my code down to something postable and understandable and forgot that...

dora c
 
myFunction( *(ppvMemoryBlock + iArrayCounter) );

I think you are referencing the middle of a word.
Why are you doing this and not
ppvMemoryBlock[iArrayCounter];

Depending on the size to store the address, doing it like you are has to increment iArrayCounter by two or four.
 
cdlvj, the two are equivalent
Though personally, I find the array notation a lot cleaner to look at.

DoraC
How do you allocate each row of the array, that is
*(ppvMemoryBlock + iArrayCounter) = calloc ....

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top