Valhalla Legends Forums Archive | C/C++ Programming | FindFile using 5Mb?! [solved]

AuthorMessageTime
gameschild
My code in memory is 700Kb until the following class is loaded and then suddenly it jumps to 5MB. I know the part where it creates a new Product and adds it is working because commenting out doesnt affect memory usage. My guess is that something isnt being free'd or the fact its recursive is meaning something isnt being freed?

Any ideas would be great.

(I know getExeName is probably ineffecient but that hasnt been optimised yet, i dont think thats the reason for the memory problems).

[code]
void Scanner::Scan(char *path, class ProductCollection *aProductCollection, class Controller *me)
{
WIN32_FIND_DATA FileData;
HANDLE hFile;
   char sTemp[MAX_PATH];
   char SearchString[MAX_PATH];
   sprintf(SearchString, "%s*", path);
   hFile = FindFirstFile(SearchString,&FileData);

if ( INVALID_HANDLE_VALUE == hFile )
      {
         return;
}

      do
      {
         if(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
         {
            sprintf(sTemp,"%s%s\\", path, FileData.cFileName);
            
            if (FileData.cFileName[0] != '.')
            {
               GetFile(sTemp, aProductCollection, me);
               Scan(sTemp, aProductCollection, me);
            }
         }
      }
      while(FindNextFile(hFile, &FileData ));
return;
}
   
int Scanner::GetFile(char *path, class ProductCollection *aProductCollection, class Controller *me)
{   
WIN32_FIND_DATA FileData;
HANDLE hFile;
   char SearchString[MAX_PATH];
   sprintf(SearchString, "%s*%s", path, "exe");
   hFile = FindFirstFile(SearchString,&FileData);

if ( INVALID_HANDLE_VALUE == hFile )
      {
   return false;
}

      do
      {
         char temp[MAX_PATH]= {'\0'};b
         sprintf(temp,"%s%s", path, FileData.cFileName);
         
         getExeName(temp);
         if(me->isProductExeOnline(temp,"1.0") )
         {
            Product* p = new Product("unknown", temp );
            aProductCollection->addProduct(p);
         }
      }
      while(FindNextFile(hFile, &FileData ));
return true;
}

inline void Scanner::getExeName(char* exePath)
{
   int t=0;
   char temp[MAX_NAME]={'\0'};
   for(int i=strlen(exePath);i>=0;i--)
   {
      if(exePath[i]=='\\')
      {
         t=strlen(exePath)-i-1;
         break;
      }
   }
   for(int i=0;i<t;i++)
   {
      temp[i]=exePath[strlen(exePath)-t+i];
   }
   strcpy(exePath, temp);
}
[/code]
July 15, 2004, 12:52 PM
gameschild
Removed GetExeName and using FileData.cFileName instead so becomes

[code]
         if(me->isProductExeOnline(FileData.cFileName,"1.0") )
         {
            myInterface->sendDbgMessage(FileData.cFileName);
            Product* p = new Product("unknown", FileData.cFileName );
            aProductCollection->addProduct(p);
         }
[/code]
July 15, 2004, 2:02 PM
gameschild
was missing

[code]
FindClose(hFile);
[/code]
July 15, 2004, 2:09 PM

Search