long long x;
Windows:
printf( "%I64d\n" , x );
Unix:
printf( "%lld\n" , x );
--
"%qd" ?
long long x;
Windows:
printf( "%I64d\n" , x );
Unix:
printf( "%lld\n" , x );
--
"%qd" ?
fopen with 'a' 無法使用 fseek 對檔案指標進行倒退嚕
這兩天運氣不怎好 總是卡在奇怪的 bug 中
真的是太嫩了 還差得遠
=========================================================
= By finwater (cheer up) @ Mon Jun 23 20:15:07 2008
=
fopen with flag 'a' 的 'a' 是 append 的意思
所以 write 的 data 會被自動 append 到檔案的最後
無論此時 offset 在哪
但還是可以使用 fseek 對 file pointer 的 offset 進行操作
=========================================================
@ code 1 : fopen with 'ab+'
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE * fd = fopen ("dd" , "ab+");
fd = fopen ("dd" , "w+");
fclose ( fd );
fd = fopen ("dd" , "ab+");
fprintf( fd , "0123456789" );
fseek( fd , -5 , SEEK_CUR );
fprintf( fd , "0123456789" );
fclose ( fd );
return 0;
}
結果: 01234567890123456789
@ code 2 : fopen wtih 'rb+'
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE * fd = fopen ("dd" , "ab+");
fd = fopen ("dd" , "w+");
fclose ( fd );
fd = fopen ("dd" , "rb+");
fprintf( fd , "0123456789" );
fseek( fd , -5 , SEEK_CUR );
fprintf( fd , "0123456789" );
fclose ( fd );
return 0;
}
結果: 012340123456789
http://www.irfanview.com/
http://www.irfanview.com/main_download_engl.htm
Step 1 :
[File] -> Batch Coversion/Rename
Step 2 :
透過右上角視窗,可以挑選待處理的照片
記得請將[檔案類型]改成 All files (*.*)
選好照片後,請點選 [Add] 或是對指定目錄點選 [Add all]
接著就會在右下角視窗記錄著
Step 3 :
目前打算將原始檔 jpg 檔轉成較小的圖檔
[Batch conversion settings] -> Output format: JPG - JPG/JPEG Format
勾選 [Use advanced options] -> Advanced
Step 4 :
設定 Advanced 參數,我常用的是將照片的寬設成 1024
[RESIZE] -> Set long side to: 1024
勾選常用選項
[Preserve aspect radio(proportional)]
[Use Resample function(better quality)]
[Don't enlarge smaller images]
Step 5 :
選擇輸出的位置
[Output directory for result files]
Step 6 :
[Start Batch]
結論:
沒事不要 truncate !
若一天有 80 萬封信且九成是 spam mail
代表一天 86400 秒 => 平均 1秒需處理約 10 次動作
目前若採用 truncating
FreeBSD 6.2-RELEASE-p1
Intel(R) Pentium(R) 4 CPU 3.00GHz (2992.51-MHz 686-class CPU)
1GB Ram
25000 次花費近 120 秒 => 1秒可處理 200 次
這個數字不曉得撐不撐得住最大量的時候 :P
若改掉的話
25000 次僅需 0.46 秒 => 1 秒可處理 54347 次
=======================================================
@ code 1 : fopen with "w"
int main()
{
int i;
FILE * fd;
for( i=0; i< 25000 ; i++ )
{
fd = fopen( "t_d.txt" , "w" );
fprintf(fd,"%d\n",i);
fclose( fd );
}
return 0;
}
# time ./a.out
0.127u 1.589s 1:57.61 1.4% 5+177k 0+25000io 0pf+0w
======================================================
@ code 2 : fopen with "a"
int main()
{
int i;
FILE * fd;
for( i=0; i< 25000 ; i++ )
{
fd = fopen( "t_d.txt" , "a" );
fprintf(fd,"%d\n",i);
fclose( fd );
}
return 0;
}
# time ./a.out
0.052u 0.410s 0:00.46 100.0% 5+188k 0+0io 0pf+0w
======================================================
--
觀看硬體資訊:
# cat /var/run/dmesg.boot
還在只靠 dmesg -a 已經落伍了 XD