我使用此代码实时打开一个记录文件,并使用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