我使用此代碼實時打開一個記錄文件,並使用FSEEK()和FTELL文件大小(),以獲得文件大小:幫助優化函數來獲取在一個循環
typedef struct _Recording Recording;
struct _Recording
{
FILE *file;
long filesize;
int progress_id;
...
};
void start_recording(Recording *recording, char* filepath)
{
...
recording->file = fopen(filepath, "rb");
recording->progress_id =
g_timeout_add (500, (GSourceFunc) progress_timeout, recording);
}
gboolean progress_timeout (Recording *recording)
{
if (recording->file != NULL)
{
fseek(recording->file, 0, SEEK_END);
recording->filesize = ftell(recording->file);
}
return TRUE;
}
void stop_recording(Recording *recording)
{
...
if (recording->file)
{
fclose (recording->file);
recording->file = NULL;
}
if (recording->progress_id != 0)
{
g_source_remove (recording->progress_id);
recording->progress_id = 0;
}
}
我使用這個函數在一個循環中(500毫秒)。需要幫助來優化功能才能更快。
代碼的效率。
與循環功能
(與代碼無關,但是..)你使用什麼編譯器?試試'gcc -O3'。 –
詳細信息:使用'long filesize;' – chux
更好使用[fstat](http://linux.die.net/man/2/fstat) – chux