View Single Post
Old 04-06-2005, 02:27 PM  
rickholio
Confirmed User
 
Industry Role:
Join Date: Jan 2004
Location: Nor'easterland
Posts: 1,914
Quote:
Originally Posted by bdjuf
got it! thanx guys

now another question, how do I reset an array? make it all empty again?
Assuming it's a contiguous area of memory and a simple array:

Code:
memset((void *)array_ptr, number_of_elements * sizeof(array_type), 0);
Alternately, you can request it be zeroed while allocating:

Code:
array_ptr = (array_type *)calloc(number_of_elements, sizeof(array_type));
You're doing c++, so you can always just destroy the old object and create a new one, which should set all values to their prototypes as well... if not, you can do the memset() thing in the object constructor.

HTH. HAND.

PS - If you malloc()'d the array originally, make sure you free() it before doing a new malloc(), otherwise you'll leak ram.

Last edited by rickholio; 04-06-2005 at 02:29 PM..
rickholio is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote