This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Doubt on using Array for 50000

Hi to all, The posting summery may be simple, but i am not able to fix the error.

Ok lets come to the problem. I am creating an Index
File "Test.txt" on Serial Flash using FILESystem which holds 50,000 datas each one is 2 bytes.

Another File is xx.txt which holds same 50,000 datas each size is 4 bytes. Using following function.

//MAX_USERS =50000

int File_Write_Index (unsigned int no_ofData)
{
        unsigned short count[MAX_USERS], i;
        FILE *fpt;

        fpt = fopen ("Test.txt","w");
    if (fpt == NULL)
    {
      printf ("File not found!. Write Failed\n");
          return 0;
    }

   else
   {
          for(i=0; i<MAX_USERS; i++)//MAX_USERS =50000
                count[i] = 0x0000 + i;

      fwrite (&count[0], 2, MAX_USERS, fpt);
          fclose (fpt);
          printf("\r\nWrite Succeed");
          return 1;
   }

}

and the second function for 4 bytes data same as first one where i change the size as 4.

fwrite (&count[0], 4, MAX_USERS, fpt);

Actually i made this function for 1000 MAX_USERS. But now i want to make it for 5000.

But Creating buffer for 50000 will increase the RAM size.
So i Created a line

unsigned long i=0;
unsigned char j;

for(k=0; k<MAX_USERS; )
{
j=(unsigned char *)&k;
fwrite (&j, 2, 1, fpt);
}

unsigned long j;

for(k=0x11111111; k<0x11111111+MAX_USERS; k++)
{
j=(unsigned char *)&k;
fwrite (&j, 2, 1, fpt);
}

But this one getting much time to read and write the files and even to search just for 1000 MAX_USERS.

   I am not able to go for more than 1000. The code does not print any errors. But its not working.

while debugging it goes to Somewhere which i dont know.

So i am here for your help and guidelines.
Please tell me how to create a line to move my 50000 no of 2 and 4 bytes of datas into my corresponding files? I am using LPC2388.


Parents
  • Sorry for my mistakes in my last posting. But thanks for your reply. I didnt look at the preview well. Sorry for that.

    What i am trying to do is I am making a index file which contains the locations of the each data in the data file.
    Each index is 2 bytes and each data is 4 bytes. So each data location is stored in the index file.
    So i am making 50000 index in the index file and 50000 datas in the data file.

    And after i succeed writing them in SD card, i just commend the write the functions and doing binary searching.

    unsigned long Data_need_2_Searched = 0x3BA60000;
    

    However i fixed that issue using the following code

    int File_Write_Index (unsigned int no_ofData)
    {
            unsigned short i;
            unsigned char *L_UC_Temp;
            FILE *fpt;
    
            fpt = fopen ("Test.txt","w");
        if (fpt == NULL)
        {
          printf ("File not found!. Write Failed\n");
              return 0;
        }
    
       else
       {
              for(i=0; i<MAX_USERS; i++)
              {
              //    count[i] = 0x0000 + i;
              L_UC_Temp = (unsigned char *)&i;
          fwrite (L_UC_Temp, 2, 1, fpt);
              }
              fclose (fpt);
              printf("\r\nWrite Succeed");
              return 1;
       }
    
    }
    

    and

    int     File_Write_UserDet (unsigned int no_ofData)
    {
            unsigned long int i;
            FILE *dat;
            unsigned char *L_UC_Temp;
    
            dat = fopen ("UserLocation.txt","w");
        if (dat == NULL)
        {
          printf ("File not found!. Write Failed\n");
              return 0;
        }
    
       else
       {
              for(i=0x3BA5B64B; i<(0x3BA5B64B + MAX_USERS); i++)
              {
    //              count[i] = 0x3BA5B64B + i;
              L_UC_Temp = (unsigned char *)&i;
          fwrite (L_UC_Temp, 4, 1, dat);
              }
              fclose (dat);
              printf("\r\nWrite Succeed");
              return 1;
       }
    
    }
    

    But still i have a problem that is if i define MAX_USERS value more than 24500, i am not able search my data without writing the 24500 datas again(i.e need to uncomment the write function ). i.e whenever i need to search the data, the code asks that write the whole data again in the file then do the searching. then I need to write the whole 24500 long value again using this function.

    File_Write_UserDet(unsigned int no_ofData)
    

    That means once if i succeed to write the index file and data file in the SD card, i am able to commend those line for searching the data in the memory(i.e no need to write it again and again).

    So with that if my MAX_USERS value is less than 24000, i am able to search the data again and again without writing them again and again.

    But if i define my MAX_USERS value more than 24000 I am not able to Search my data without writing them again and again.

    Simply it says data not available.

    I did writing the MAX_USERS no of data file in SD card only once. This is enough to search below 24000 datas.

    I am not able to continue this with more that 24000 value.

    So i need to fix this error. please help. if my posting is not quite clear means please ask me.

Reply
  • Sorry for my mistakes in my last posting. But thanks for your reply. I didnt look at the preview well. Sorry for that.

    What i am trying to do is I am making a index file which contains the locations of the each data in the data file.
    Each index is 2 bytes and each data is 4 bytes. So each data location is stored in the index file.
    So i am making 50000 index in the index file and 50000 datas in the data file.

    And after i succeed writing them in SD card, i just commend the write the functions and doing binary searching.

    unsigned long Data_need_2_Searched = 0x3BA60000;
    

    However i fixed that issue using the following code

    int File_Write_Index (unsigned int no_ofData)
    {
            unsigned short i;
            unsigned char *L_UC_Temp;
            FILE *fpt;
    
            fpt = fopen ("Test.txt","w");
        if (fpt == NULL)
        {
          printf ("File not found!. Write Failed\n");
              return 0;
        }
    
       else
       {
              for(i=0; i<MAX_USERS; i++)
              {
              //    count[i] = 0x0000 + i;
              L_UC_Temp = (unsigned char *)&i;
          fwrite (L_UC_Temp, 2, 1, fpt);
              }
              fclose (fpt);
              printf("\r\nWrite Succeed");
              return 1;
       }
    
    }
    

    and

    int     File_Write_UserDet (unsigned int no_ofData)
    {
            unsigned long int i;
            FILE *dat;
            unsigned char *L_UC_Temp;
    
            dat = fopen ("UserLocation.txt","w");
        if (dat == NULL)
        {
          printf ("File not found!. Write Failed\n");
              return 0;
        }
    
       else
       {
              for(i=0x3BA5B64B; i<(0x3BA5B64B + MAX_USERS); i++)
              {
    //              count[i] = 0x3BA5B64B + i;
              L_UC_Temp = (unsigned char *)&i;
          fwrite (L_UC_Temp, 4, 1, dat);
              }
              fclose (dat);
              printf("\r\nWrite Succeed");
              return 1;
       }
    
    }
    

    But still i have a problem that is if i define MAX_USERS value more than 24500, i am not able search my data without writing the 24500 datas again(i.e need to uncomment the write function ). i.e whenever i need to search the data, the code asks that write the whole data again in the file then do the searching. then I need to write the whole 24500 long value again using this function.

    File_Write_UserDet(unsigned int no_ofData)
    

    That means once if i succeed to write the index file and data file in the SD card, i am able to commend those line for searching the data in the memory(i.e no need to write it again and again).

    So with that if my MAX_USERS value is less than 24000, i am able to search the data again and again without writing them again and again.

    But if i define my MAX_USERS value more than 24000 I am not able to Search my data without writing them again and again.

    Simply it says data not available.

    I did writing the MAX_USERS no of data file in SD card only once. This is enough to search below 24000 datas.

    I am not able to continue this with more that 24000 value.

    So i need to fix this error. please help. if my posting is not quite clear means please ask me.

Children