c程序连接mysql,内存占用问题 linux下写的c程序连接mysql , 内存占用很大100多m, 这咋回事mysql_free_result mysql_close 都有的。。 但是一开开 ,内存总是这么大 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在linux环境 mysql_free_resultmysql_close都用了,内存也没涨 但是太大了 始终100多M #include <stdio.h>#include <pthread.h>#include <mysql/mysql.h>void *test1( void *arg ){ char sql[1024]; MYSQL_RES *results; MYSQL_ROW record; unsigned long id = 0; MYSQL *mysql; int mysql_timeout = 10; mysql = mysql_init( NULL ); mysql_options( mysql, MYSQL_OPT_CONNECT_TIMEOUT, &mysql_timeout ); if ( !mysql_real_connect( mysql, "localhost", "root", "123456","db", 0, NULL, 0 ) ) { printf("error"); exit(1); } while( 1 ) { snprintf( sql, 1024, "select * from test limit %ld,10", id ++ ); if ( mysql_query( mysql, sql ) != 0 ) { printf( "1 mysql:%s\n", mysql_error( mysql ) ); } results = mysql_store_result( mysql ); if ( results == NULL ) { printf( "2 mysql:%s\n", mysql_error( mysql ) ); } while ( (record = mysql_fetch_row( results ) ) ) { printf("%s - %s\n", record[0], record[1] ); } if ( mysql_num_rows( results ) == 0 ) { id = 0; } mysql_free_result( results ); } return arg;}void *test2( void *arg ){ char sql[1024], str[1024]; int id = 0; MYSQL *mysql; int mysql_timeout = 10; mysql = mysql_init( NULL ); mysql_options( mysql, MYSQL_OPT_CONNECT_TIMEOUT, &mysql_timeout ); sleep( 2 ); if ( !mysql_real_connect( mysql, "localhost", "root", "wangwei","wang", 0, NULL, 0 ) ) { printf("error"); exit(1); } while ( 1 ) { snprintf( str, 1024, "wangwei %d", id ); snprintf( sql, 1024, "insert into test values (%ld,'%s')", id ++, str ); if ( mysql_query( mysql, sql ) != 0 ) { printf( "1 mysql:%s\n", mysql_error( mysql ) ); } printf("+"); } return arg;}main(){ int status; pthread_t id1, id2; printf("mysql_thread_safe = %d\n",mysql_thread_safe()); status = pthread_create( &id1, NULL, test1, NULL ); if (status != 0) { perror("thread1"); exit(0); } status = pthread_create( &id2, NULL, test2, NULL ); if (status != 0) { perror("thread2"); exit(0); } while(1);}家里电脑180M 公司电脑小一些 很奇怪 凡是连mysql的程序 个个都100多m 诶 mysq连接参数autoReconnectForPools到底有什么用 求高手帮忙mysql 1064错误,小弟感激不尽! 请教一个强制用户退出的问题 hql问题 提交中文到数据库产生乱码 smallint型数据转换成字符串类型有什么函数?【postgresql】 在postgresql里,日期前后能用 > 和 < 做比较吗? Redhat7.2下,编译安装mysql-3.23.51失败,请教高手! mysql外键设置 需求描述,请提供60秒内,同一个用户出现5次及以上记录的数据 mysql 基本表数据更新 视图不随之更新 linux下odbc SQLConnect问题
mysql_free_result
mysql_close
都用了,内存也没涨 但是太大了 始终100多M
#include <pthread.h>
#include <mysql/mysql.h>
void *test1( void *arg )
{
char sql[1024];
MYSQL_RES *results;
MYSQL_ROW record;
unsigned long id = 0;
MYSQL *mysql;
int mysql_timeout = 10;
mysql = mysql_init( NULL ); mysql_options( mysql, MYSQL_OPT_CONNECT_TIMEOUT, &mysql_timeout ); if ( !mysql_real_connect( mysql, "localhost", "root", "123456","db", 0, NULL, 0 ) )
{
printf("error");
exit(1);
}
while( 1 )
{
snprintf( sql, 1024, "select * from test limit %ld,10", id ++ );
if ( mysql_query( mysql, sql ) != 0 )
{
printf( "1 mysql:%s\n", mysql_error( mysql ) );
}
results = mysql_store_result( mysql ); if ( results == NULL )
{
printf( "2 mysql:%s\n", mysql_error( mysql ) );
} while ( (record = mysql_fetch_row( results ) ) )
{
printf("%s - %s\n", record[0], record[1] );
} if ( mysql_num_rows( results ) == 0 )
{
id = 0;
}
mysql_free_result( results );
} return arg;
}void *test2( void *arg )
{
char sql[1024], str[1024];
int id = 0;
MYSQL *mysql;
int mysql_timeout = 10;
mysql = mysql_init( NULL ); mysql_options( mysql, MYSQL_OPT_CONNECT_TIMEOUT, &mysql_timeout ); sleep( 2 );
if ( !mysql_real_connect( mysql, "localhost", "root", "wangwei","wang", 0, NULL, 0 ) )
{
printf("error");
exit(1);
}
while ( 1 )
{
snprintf( str, 1024, "wangwei %d", id );
snprintf( sql, 1024, "insert into test values (%ld,'%s')", id ++, str ); if ( mysql_query( mysql, sql ) != 0 )
{
printf( "1 mysql:%s\n", mysql_error( mysql ) );
}
printf("+");
}
return arg;
}
main()
{
int status;
pthread_t id1, id2; printf("mysql_thread_safe = %d\n",mysql_thread_safe());
status = pthread_create( &id1, NULL, test1, NULL );
if (status != 0)
{
perror("thread1");
exit(0);
} status = pthread_create( &id2, NULL, test2, NULL ); if (status != 0)
{
perror("thread2");
exit(0);
} while(1);
}
家里电脑180M 公司电脑小一些 很奇怪 凡是连mysql的程序 个个都100多m 诶