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 诶 唯一性太差的字段不宜建立索引的原因 mysql键值排序问题,求解答。 mysql某字段设置为“唯一”后,就无法再插入相同记录了吗?? 请教在mysql中,怎样使用全文搜索搜索中文内容 MYSQL中varchar字段的“张琳”和“张敏”竟然是一样的! MySql最新的简体中文版本号是多少,哪有下载地址。我要下!!! 如何在进行表更新操作时把表锁定,有这样的命令么? 急!! 问PHP+MYSQL查找的一个算法 数据库分表设计的问题 求mysql怎么查2周数据 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 诶