memcached Óëc/c++ÔËÓÃ
ÐÞ¸Ämakefile£¬ÔÚLIBSÀïÃæ¼ÓÉÏ-lmemcached£¬±ÈÈçÔÀ´ gcc test.c£¬ÏÖÔÚ gcc test.c -lmemcached¡£Õâ¸ö¿â¾ÍÊÇlibmemcachedÌṩµÄ¡£
È»ºóÌí¼Ó#include<libmemcached/memcached.h>£¬Õâ¸öÎļþÒ²ÊÇlibmemcachedÌṩµÄ¡£
Ö÷º¯ÊýÀïÃæÐèÒªÌí¼Ó£º
memcached_st *memc;
uint32_t flags;
memcached_return rc;
memcached_server_st *servers;
memc= memcached_create(NULL);
servers= memcached_servers_parse("127.0.0.1:12300");
memcached_server_push(memc, servers);
memcached_server_list_free(servers);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 0);
Õâ¾ÍÊdzõʼ»¯µÄÈ«²¿´úÂ룬¿ÉÒÔÉèÖúܶණÎ÷£¬²»¹ýÎÒÏÖÔÚÖ»ÒªÒ»¸ö·þÎñÆ÷£¬¾Í¿´Ò»¾ä»°£º
servers= memcached_servers_parse("127.0.0.1:12300");
Õâ¾ÍÊÇÖ¸Ã÷ÒªÁ¬½Óµ½Î»ÓÚ127.0.0.1¼àÌý12300¶Ë¿ÚµÄmemcached³ÌÐò. ÆäËû¶¼²»¹Ü¡£
×îºóÓÃÒ»¶ÎÐ޸ĺóµÄ´úÂë½éÉÜÁ½¸öº¯Êý£¬memcached_getºÍmemcached_set£¬¶¼¿ÉÒÔman³öÀ´¡£
char * result_str; /*Õâ¸ö¾ÍÊDzéѯµÄ½á¹û*/
std::string query="Òª²éѯµÄÊý¾ÝÃû";
result_str= memcached_get(memc, query.c_str(), strlen(query.c_str()),
&result_str_length, &flags, &rc);
if (rc == MEMCACHED_SUCCESS)
{
printf("%s",result_str);
free(result_str); /*Ò»¶¨Òªfreeµô memcached´«»ØµÄÊý¾Ý*/
continue;
}
else if (rc == M
Ïà¹ØÎĵµ£º
#include <assert.h>¡¡¡¡¡¡¡¡//É趨²åÈëµã
#include <ctype.h>¡¡¡¡¡¡¡¡ //×Ö·û´¦Àí
#include <errno.h>¡¡¡¡¡¡¡¡ //¶¨Òå´íÎóÂë
#include <float.h>¡¡¡¡¡¡¡¡ //¸¡µãÊý´¦Àí
#include <fstream.h>¡¡¡¡¡¡ //ÎļþÊäÈ룯Êä³ö
#include  ......
extern cµÄ×÷Óá¾×ª¡¿
2009-12-18 13:10
1.ÒýÑÔ
C++ÓïÑԵĴ´½¨³õÖÔÊÇ“a better C”£¬µ«ÊÇÕâ²¢²»Òâζ×ÅC++ÖÐÀàËÆCÓïÑÔµÄÈ«¾Ö±äÁ¿ºÍº¯ÊýËù²ÉÓõıàÒëºÍÁ¬½Ó·½Ê½ÓëCÓïÑÔÍêÈ«Ïàͬ¡£×÷ΪһÖÖÓûÓëC¼æÈݵÄÓïÑÔ£¬C++±£ÁôÁËÒ»²¿·Ö¹ý³Ì ʽÓïÑÔµÄÌص㣨±»ÊÀÈ˳ÆΪ“²»³¹µ×µØÃæÏò¶ÔÏ󔣩£¬Òò¶øËü¿ÉÒÔ¶¨Òå²»ÊôÓ ......
CºÍC++»¥Ïàµ÷Óú¯Êýʱ£¬Ê¹ÓÃextern "C"¡£
ÔÒò£º
C²»Ö§³Öº¯ÊýÖØÔØ£¬¶øC++Ö§³Öº¯ÊýÖØÔØ¡£º¯Êý±»C++±àÒëºó»áÃû×ÖÓëCÓïÑÔ²»Í¬¡£¼ÙÉèijº¯ÊýÔÐÍΪfoo(ing x, int y)£¬±»C++±àÒëºóÃû×ÖΪ_foo_int_int£¬¶øC±àÒëÆ÷±àÒëºóÃû×ÖΪ_foo¡£ ......
¹¹½¨»ù±¾µÄLinux C ±à³Ì»·¾³ ÊÕ²Ø
±¾ÎÄ»ùÓÚdebian-40r0(ÄÚºË2.6.18)½éÉÜÒ»ÏÂÈçºÎÔÚÒ»¸ö±ê׼ϵͳÖй¹½¨Linux CµÄ»ù±¾±à³Ì¿ª·¢»·¾³¡£
Ò»¸öÍêÕûµÄ¿ª·¢»·¾³Ö÷Òª°üÀ¨Ëĸö²¿·Ö£º±ê×¼C¿â¡¢Í·Îļþ¡¢¹¤¾ßÁ´¡¢±à¼Æ÷¡¢°ïÖúÎĵµ£¬ÏÂÃæÒÀ´Î½éÉÜ¡£
±ê×¼C¿âglibc
glibcÊÇgnu·¢²¼µÄlibc¿â£¬¼´cÔËÐп⡣glibcÊÇlinuxϵͳÖÐÄÚºËÖ ......
1.ÇóÏÂÃ溯ÊýµÄ·µ»ØÖµ£¨Î¢Èí£©
int func(x)
{
int countx = 0;
while(x)
{
countx ++;
x = x&(x-1);
}
......