As far as I know, the general procedure follows:
Step 2: Split the string (separate the numbers by whitespace) up into the individual entries, placing the individual entries into a raw array of strings. Call this array RAWARRAYOFSTRINGS
Step 3: Convert all the array entries into numbers and place them in the proper numeric array for further use in the program. Call this array NUMERICARRAYTHATWILLBEUSEDINPROGRAM
However, this check only happens at Step 3, when NUMERICARRAYTHATWILLBEUSEDINPROGRAM is filled.
I would like to try something different; I would like to start using dynamic arrays. However, I am wondering what checks to include to ensure the memory allocation can be performed. And if it cannot, how do I code the program so that it fails gracefully?
For example, say a user tries to deliberately break the program. He copies and pastes a HUGE block of numbers from an e-book. Some scenarios:
(i) TEXTAREABOXSTRING is so huge, the user doesn't have enough memory and the program fails.
(ii) The program accepts TEXTAREABOXSTRING okay, but there is not enough memory for both TEXTAREABOXSTRING and RAWARRAYOFSTRINGS. So the program fails at Step 2.
(iii) The program accepts TEXTAREABOXSTRING and RAWARRAYOFSTRINGS okay, but there is not enough memory for TEXTAREABOXSTRING, RAWARRAYOFSTRINGS, and NUMERICARRAYTHATWILLBEUSEDINPROGRAM. So the program fails at Step 3.
In fact, triple the memory is being used for the same data even though it is only the numeric array that will be used in the program (once it is filled).
Is there a way to de-allocate memory being used by TEXTAREABOXSTRING? It is not going to be used later in the program and I would like to reduce the chance that a memory allocation error might happen later.
What can I do to ensure memory allocation failures happen gracefully?
(Should I even worry about it, or is it handled internally by the browser?)