0


I am calling a function recursively and which is allocating 2048 byte is being allocated in each call.At start the application is running as per requirement but later it is getting crashed by giving the error that "Not enough storage is available to process this command". And the memory allocator returns bad pointer of memory,for which the application is being crashed.can any one please help me on this issue.

char* parser(char *data){
   char *string,*ptr,*result;
   int len;

   len=strlen(data);
   ptr=strstr(data,"search");

   if(ptr){
    buf = (char *)GlobalAlloc(GPTR,sizeof(char)*len+1);
    strncpy(buf,data,ptr-data);
    buf[ptr-data]='\0';
    result=parser(buf); 
    GlobalFree(buf);
    return result;
  }
}
Subrat nayak.
  • 405
  • 1
  • 7
  • 25
  • possible duplicate of [System Error. Code: 8. Not enough storage is available to process this command](http://stackoverflow.com/questions/507853/system-error-code-8-not-enough-storage-is-available-to-process-this-command) – Shiplu Mokaddim Apr 17 '12 at 09:34

1 Answers1

3

Well ... It's kind of obvious:

Don't call the function so many times, without also freeing the memory used as soon as it's no longer needed. If the allocations done by the calls are all needed at the same time (once the recursion completes), then you're out of luck and need to either:

  • buy more memory,
  • figure out a more compact representation,
  • divide the solving into smaller steps.
unwind
  • 391,730
  • 64
  • 469
  • 606