Example #1
0
void SimpleString_append_c (SimpleString me, const char32 *str) {
	if (! str) {
		return;
	}
	long myLength = str32len (my string);
	my string = (char32 *) Melder_realloc (my string, (myLength + str32len (str) + 1) * (int64) sizeof (char32));
	str32cpy (& my string[myLength], str);
}
Example #2
0
void NUMvector_append (long elementSize, void **v, long lo, long *hi) {
	try {
		char *result;
		if (! *v) {
			result = reinterpret_cast <char *> (NUMvector (elementSize, lo, lo));
			*hi = lo;
		} else {
			long offset = lo * elementSize;
			for (;;) {   // not very infinite: 99.999 % of the time once, 0.001 % twice
				result = reinterpret_cast <char *> (Melder_realloc ((char *) *v + offset, (*hi - lo + 2) * elementSize));
				if ((result -= offset) != nullptr) break;   // this will normally succeed at the first try
				(void) Melder_realloc_f (result + offset, 1);   // make "sure" that the second try will succeed
			}
			(*hi) ++;
			memset (result + *hi * elementSize, 0, elementSize);   // initialize the new element to zeroes
		}
		*v = result;
	} catch (MelderError) {
		Melder_throw (U"Vector: element not appended.");
	}
}
Example #3
0
static void NUMvector_extendNumberOfElements (long elementSize, void **v, long lo, long *hi, long extraDemand)
{
	try {
		char *result;
		if (! *v) {
			long newhi = lo + extraDemand - 1;
			result = reinterpret_cast <char *> (NUMvector (elementSize, lo, newhi));
			*hi = newhi;
		} else {
			long offset = lo * elementSize;
			for (;;) {   // not very infinite: 99.999 % of the time once, 0.001 % twice
				result = reinterpret_cast <char *> (Melder_realloc ((char *) *v + offset, (*hi - lo + 1 + extraDemand) * elementSize));
				if ((result -= offset)) break;   // this will normally succeed at the first try
				(void) Melder_realloc_f (result + offset, 1);   // ??make "sure" that the second try will succeed
			}
			(*hi) += extraDemand;
			memset (result + *hi * elementSize, 0, elementSize);   // initialize the new elements to zeroes
		}
		*v = result;
	} catch (MelderError) {
		Melder_throw (U"Vector: size not extended.");
	}
}
Example #4
0
void Minimizer_minimize (Minimizer me, long maxNumOfIterations, double tolerance, int monitor) {
	try {

		my tolerance = tolerance;
		if (maxNumOfIterations <= 0) {
			return;
		}

		if (my iteration + maxNumOfIterations > my maxNumOfIterations) {
			double *history;
			my maxNumOfIterations += maxNumOfIterations;
			if (my history) {
				my history++;    /* arrays start at 1 !! */
			}
			history = (double *) Melder_realloc (my history, my maxNumOfIterations *
			                                     sizeof (double));
			my history = --history; /* arrays start at 1 !! */
		}
		if (monitor) {
			my gmonitor = (Graphics) Melder_monitor (0.0, L"Starting...");
		}
		my start = 1; /* for my after() */
		my v_minimize ();
		if (monitor) {
			monitor_off (me);
		}
		if (my success) Melder_casual ("Minimizer_minimize: minimum %f reached \n"
			                               "after %ld iterations and %ld function calls.", my minimum,
			                               my iteration, my funcCalls);
	} catch (MelderError) {
		if (monitor) {
			monitor_off (me);    // temporarily until better monitor facilities
		}
		Melder_clearError(); // memory error in history mechanism is not fatal
	}
}
Example #5
0
const char32 *SimpleString_genericize_c (SimpleString me) {
	autoSimpleString thee = Data_copy (me);
	my string = (char32 *) Melder_realloc (my string, (3 * str32len (my string) + 1) * (int64) sizeof (char32));
	Longchar_genericize32 (thy string, my string);
	return my string;
}