LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

File Binary conversion

Hello everyone,
I have a problem with my CVI project and I hope that someone can help me. I have to open a file *.bin so I have written these portion of code:

......
......

fp=fopen("C:/file1.bin","rb");

if (fp)
    {
    fseek(fp,0,SEEK_END);
    DimFile=ftell(fp);
    rewind(fp);
    }

FilePtr=malloc(DimFile);
ByteRead=fread(FilePtr,1,DimFile,fp);

but  I have to read the original  file in binary way, this mean that every element pointed by FilePtr has to be a single bit (0/1) so I have inserted this simple conversion byte-->bit:

Data=malloc(DimFile*8);

for (k=0;k<DimFile;k++)
    {
    for (i=0;i<8;i++)
        *(Data +(k*8+i))=( (*(FilePtr + k)>>(i))& 0x01 );  
    }

the file is about 15 MB and the problem is quite simple: I have tested this code on Linux (gcc compiler) and also on Windows Xp (lcc compiler) and in both it's executed in less than 1 second but if I runs it in CVI it takes 40 seconds on the same machine and with the same file. Why??
Thanks in advance.

 





Message Edited by aldart on 08-16-2007 09:54 AM

0 Kudos
Message 1 of 4
(3,471 Views)
Are you running in Debug or Release mode? Debug adds a lot of run-time checking around your code so I would not be surprised by the extra time taken. Release mode should be significantly quicker, but you probably would not achieve the same performance levels as with the other compilers you mentioned.
 
JR
0 Kudos
Message 2 of 4
(3,465 Views)
I'd add that if speed is important, you may want to investigate the "Build >> External Compiler Support" feature from the CVI menu.  (CVI's native compiler is not an optimizing one.)

Message Edited by Ian W on 08-16-2007 11:27 AM

0 Kudos
Message 3 of 4
(3,461 Views)
Yes I was running in debug mode. I have changed Configuration in Release mode and the execution time is gone to 3 seconds. Thank you very much and sorry but I'm newbie and I'm learning CVI
0 Kudos
Message 4 of 4
(3,453 Views)