![]() |
Heap Size error
Hi Guru's,
Below find function to replace string, this function is called using an ETL application and replaces the string and was working fine for low volumes() but if volumes are big it errors out with Heap allocation failure, Can you someone suggest what I've missed or need to avoid or Is there a better way to do so. Code:
Regards.... |
Re: Heap Size error
The problem is most likely the last line of that function. You can not put any executable code after that return statement. And besides, what good is it to free the pointer before the calling function has a chance to use it? It is the calling function's responsibility to free the memory for that pointer after it is done with it.
Code:
void foo() |
Re: Heap Size error
Great response, Thanks for that I will try and let you know.
|
Re: Heap Size error
I tried no luck, still have the same heap error.
|
Re: Heap Size error
What exactly is that function supposed to do? Replace one substring with another? such as replace "John" with "Henry"? What to do when the new substring is not the same length as the old one? It would seem that variable result is not being allocated anough space to hold the potentially expanded string.
One thing you can try is to increase the amount of memory malloc()'ed at the beginning of that function. char *result = malloc((strlen(str) + 32)); Two things to note here: (1) C language does not need typecasting void* returns. (2) sizeof(char) is guarendeed by c standard to be 1. So multiplying something by sizeof(char) is the same as multiplying something by 1. Both are useless statements. If adding the additional bytes to the result doesn't fix the problem then write a small program that illustrates the problem and post it here so that we can test it. Also don't forget to post the test data you are using. |
| All times are GMT +5.5. The time now is 19:28. |