- Local time
- Today, 05:04
- Joined
- Feb 28, 2001
- Messages
- 27,463
The most expensive string function is the one that produces the most strings as variables. Taking a string apart one character at a time and storing each character separately causes the following steps for EACH character: (1) Allocate memory for the string descriptor. (2) Allocate memory for the actual (sub) string to be created. (3) Extract the sub-string into the allocated slot. (4) Update the string-length slot in the descriptor. NOTE that steps 1 and 2 must allocate a new string area each time and cannot re-use previously allocated memory due to the possibility that each new string is potentially longer than the previous one. (Its a long tale of woe. You don't want to hear it.)
But the worst part isn't that memory allocation. It is the part where you are done with the strings and have to release them. The problem is that as variables, they usually are stored in the programming structure called the HEAP and occupy that space for the remainder of the session. If you do this enough you see a message about "HEAP OVERFLOW" or "STACK / HEAP COLLISION" or some other similar message that has changed over the years but still means "you blew out your heap work space." The message you get varies depending on which facility (or even which library) sensed the overlap of the stack and heap address range.
But the worst part isn't that memory allocation. It is the part where you are done with the strings and have to release them. The problem is that as variables, they usually are stored in the programming structure called the HEAP and occupy that space for the remainder of the session. If you do this enough you see a message about "HEAP OVERFLOW" or "STACK / HEAP COLLISION" or some other similar message that has changed over the years but still means "you blew out your heap work space." The message you get varies depending on which facility (or even which library) sensed the overlap of the stack and heap address range.