Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB
ÈÈÃűêÇ©£º c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 ×îÐÂÎÄÕ : c

½ñÌìÍíÉÏÔÙÓÃc ʵÏÖÒ»±é


#include <iostream>
#include <conio.h>
using namespace std;
typedef struct _INTTEST
{
        int a;        
}inttest;
int main()
{
    inttest* p=new inttest[3];
    p[1].a=10;
    cout<<p[1].a<<endl;
    getch();
    return 0;    
}
......

Linux C ʵÏÖÏ̳߳Ø

×î½ü×öµÄһЩ¹¤×÷ÐèÒªÓõ½Ï̳߳ؼ¼Êõ£¬Òò´Ë²Î¿¼ÁËһЩ×ÊÁϺÍÊé¼®£¬È硶0bug c/c++ÉÌÓù¤³ÌÖ®µÀ¡·¡£
Ϊ´ËÔÚlinuxƽ̨ÉÏÓô¿cдÁËÒ»¸öÏ̳߳صÄʵÏÖ¡£
ÔÚ´ËÁгöÁËÔ­´úÂë¡£
Ö÷ÒªÓõ½µÄÊý¾Ý½á¹¹ÓÐ
1.struct  thread_pool_t    // thread pool µÄʵÏÖ´úÂë
2.struct thread_pool_token_t    //ÔÚthread pool ÖÐÓõ½µÄ½á¹¹£¬Ò»¸ö¸ÃÀàÐͱäÁ¿´ú±íÒ»ÌõÏß³Ì
3.struct thread_pool_job_t     //µ±ÏßÇ°³Ì´¦Àí¸ÃÈÎÎñ½«»Øµ÷½á¹¹
Éè¼Æ˼·£º
Ö÷Ï̴߳´½¨Ï̳߳صĿØÖÆỊ̈߳¬
¹ÜÀíÏ߳̽«½øÈëÑ­»·À´×öÒÔÏÂÊÂÇ飺
1.Èç¹ûµ±Ç°¿ÕÏнø³Ì²»×ã²¢ÇÒ×ÜÏß³ÌÊýûÓдﵽÉÏÏÞ£¬½«´´½¨Ò»Ìõ¿ÕÏÐỊ̈߳¬ÖÁµÀ¿ÕÏÐÏ̴߳ﵽ3Ìõ£¨¼ûTHREAD_POOL_MIN_IDLE_SIZE£©
2.²»¶Ï¼ì²é¹¤×÷ÈÎÎñ¶ÓÁУ¬ÓÐÔò°²ÅÅÒ»Ìõ¿ÕÏÐÏ̶߳ԸÃÈÎÎñ½øÐд¦Àí
ÆÕͨÏ̱߳»¹ÜÀíÏ̴߳´½¨ºóÒ²½«½øÈëÑ­»·À´×öÒÔÏÂÊÂÇ飺
1.¼ì²éµ±Ç°assignµÄthread_pool_token_t½á¹¹µÄ״̬£¬Èç¹ûÊÇTREAD_POOL_STATE_BUSYÔòµ÷ÓÃthread_pool_token_tËù×¢²áµÄ»Øµ÷º¯ÊýÀ´´¦ÀíÈÎÎñ¡£
2.Íê³É¸ÃÈÎÎñºó¼ì²âµ±Ç°¿ÕÏнø³Ì¹»²»¹»£¬Èç¹ûÌ«¶àÔòÍ˳ö±¾Ị̈߳¬·ñÔò»á¸ÄдÔËÐÐ״̬ΪTREAD_POOL_STATE_IDLEºó¼ÌÐøÑ­»·
× ......

Linux C ʵÏÖÏ̳߳Ø

×î½ü×öµÄһЩ¹¤×÷ÐèÒªÓõ½Ï̳߳ؼ¼Êõ£¬Òò´Ë²Î¿¼ÁËһЩ×ÊÁϺÍÊé¼®£¬È硶0bug c/c++ÉÌÓù¤³ÌÖ®µÀ¡·¡£
Ϊ´ËÔÚlinuxƽ̨ÉÏÓô¿cдÁËÒ»¸öÏ̳߳صÄʵÏÖ¡£
ÔÚ´ËÁгöÁËÔ­´úÂë¡£
Ö÷ÒªÓõ½µÄÊý¾Ý½á¹¹ÓÐ
1.struct  thread_pool_t    // thread pool µÄʵÏÖ´úÂë
2.struct thread_pool_token_t    //ÔÚthread pool ÖÐÓõ½µÄ½á¹¹£¬Ò»¸ö¸ÃÀàÐͱäÁ¿´ú±íÒ»ÌõÏß³Ì
3.struct thread_pool_job_t     //µ±ÏßÇ°³Ì´¦Àí¸ÃÈÎÎñ½«»Øµ÷½á¹¹
Éè¼Æ˼·£º
Ö÷Ï̴߳´½¨Ï̳߳صĿØÖÆỊ̈߳¬
¹ÜÀíÏ߳̽«½øÈëÑ­»·À´×öÒÔÏÂÊÂÇ飺
1.Èç¹ûµ±Ç°¿ÕÏнø³Ì²»×ã²¢ÇÒ×ÜÏß³ÌÊýûÓдﵽÉÏÏÞ£¬½«´´½¨Ò»Ìõ¿ÕÏÐỊ̈߳¬ÖÁµÀ¿ÕÏÐÏ̴߳ﵽ3Ìõ£¨¼ûTHREAD_POOL_MIN_IDLE_SIZE£©
2.²»¶Ï¼ì²é¹¤×÷ÈÎÎñ¶ÓÁУ¬ÓÐÔò°²ÅÅÒ»Ìõ¿ÕÏÐÏ̶߳ԸÃÈÎÎñ½øÐд¦Àí
ÆÕͨÏ̱߳»¹ÜÀíÏ̴߳´½¨ºóÒ²½«½øÈëÑ­»·À´×öÒÔÏÂÊÂÇ飺
1.¼ì²éµ±Ç°assignµÄthread_pool_token_t½á¹¹µÄ״̬£¬Èç¹ûÊÇTREAD_POOL_STATE_BUSYÔòµ÷ÓÃthread_pool_token_tËù×¢²áµÄ»Øµ÷º¯ÊýÀ´´¦ÀíÈÎÎñ¡£
2.Íê³É¸ÃÈÎÎñºó¼ì²âµ±Ç°¿ÕÏнø³Ì¹»²»¹»£¬Èç¹ûÌ«¶àÔòÍ˳ö±¾Ị̈߳¬·ñÔò»á¸ÄдÔËÐÐ״̬ΪTREAD_POOL_STATE_IDLEºó¼ÌÐøÑ­»·
× ......

C ÓïÑÔ malloc ºÍ freeº¯Êýdz̸

À´×Ôbccn CÓïÑÔÂÛ̳
Ê×ÏÈÉùÃ÷Ò»µã£¬±¾ÎÄΪתÌù¡£
dz̸CÖеÄmallocºÍfree
×÷Õߣºlj_860603    ÔĶÁÈ˴Σº43013    ÎÄÕÂÀ´Ô´£º±¾Õ¾Ô­´´    ·¢²¼Ê±¼ä£º2006-8-5    ÍøÓÑÆÀÂÛ(32)Ìõ
Ô­Ìû¼°ÌÖÂÛ£ºhttp://bbs.bccn.net/thread-82212-1-1.html
    ÔÚCÓïÑÔµÄѧϰÖУ¬¶ÔÄÚ´æ¹ÜÀíÕⲿ·ÖµÄ֪ʶÕÆÎÕÓÈÆäÖØÒª£¡Ö®Ç°¶ÔCÖеÄmalloc()ºÍfree()Á½¸öº¯ÊýµÄÁ˽âÉõÉÙ£¬Ö»ÖªµÀ´ó¸Å¸ÃÔõôÓ×—¾ÍÊÇmallocÈ»ºófree¾ÍÒ»ÇÐOKÁË¡£µ±È»ÏÖÔÚ¶ÔÕâÁ½¸öº¯ÊýµÄÌå»áÒ²²»¼ûµÃ¶à£¬²»¹ý¶ÔÓÚ±¾ÎÄÕµÚÈý²¿·ÖµÄÄÚÈݵ¹ÊÇÓÐÁËתÕÛÐÔµÄÈÏʶ£¬ËùÒÔ
дÏÂÕâƪÎÄÕÂ×÷Ϊһ¸ö¶Ô֪ʶµÄ×ܽᡣÕâƪÎÄÕÂÖ®ËùÒÔÃüÃûÖÐÓиö“dz̸”µÄ×ÖÑÛ£¬Ò²¾ÍÊÇÕâ¸öÒâ˼ÁË£¡Ï£Íû¶Ô´ó¼ÒÓÐÒ»µã°ïÖú£¡
     Èç¹û²»³¶µÃÌ«Ô¶µÄ»°£¨±ÈÈç˵²Ù×÷ϵͳÖÐÐéÄâÄÚ´æºÍÎïÀíÄÚ´æÈçºÎÔË×öÈçºÎ¹ÜÀíÖ®ÀàµÄ֪ʶµÈ£©£¬ÎҸоõÕâƪÎÄÕÂÓ¦¸ÃÊDZȽÏÈ«ÃæµØ̸ÁËÒ»ÏÂmalloc()ºÍfree().ÕâƪÎÄÕÂÓÉdzÈëÉ²»¼ûµÃÓжàÉ·ÖÈý¸ö²¿·Ö½éÉÜÖ÷ÒªÄÚÈÝ¡£
·Ï»°ÁËÄÇô¶à£¬ÏÂÃæÁ¢¿Ì½øÈëÖ÷Ìâ================¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡·¡ ......

CÖеÄϸ½Ú£¬ÎÒȷʵ²»ÖªµÀ

ÏÂÃæ˵µ½µÄCÓïÑÔÖеÄ֪ʶ£¬ÎÒÖ»ÊÇÔÚ¹¤×÷Öо­³£¼ûµ½»òÓõ½£¬µ«´ÓδÉΪʲô£¬½ñÌì²ÅÈ´µÀÔ­À´¼ò¼òµ¥µ¥ÏÂÃæÔÐÓýÕâÎÞÇîµÄ֪ʶµãºÍÎÒµÄäµã£¬ÊǸñßѧϰ±ß¼Ç¼ÁË¡£
Ô¤´¦ÀíÆ÷£¨Preprocessor£©
1 . ÓÃÔ¤´¦ÀíÖ¸Áî#define ÉùÃ÷Ò»¸ö³£Êý£¬ÓÃÒÔ±íÃ÷1ÄêÖÐÓжàÉÙÃ루ºöÂÔÈòÄêÎÊÌ⣩
         #define SECONDS_PER_YEAR (60 * 60 * 24 * 365)UL
ÎÒÔÚÕâÏë¿´µ½¼¸¼þÊÂÇ飺
1) #define Óï·¨µÄ»ù±¾ÖªÊ¶£¨ÀýÈ磺²»ÄÜÒԷֺŽáÊø£¬À¨ºÅµÄʹÓ㬵ȵȣ©
2)¶®µÃÔ¤´¦ÀíÆ÷½«ÎªÄã¼ÆËã³£Êý±í´ïʽµÄÖµ£¬Òò´Ë£¬Ö±½Óд³öÄãÊÇÈçºÎ¼ÆËãÒ»ÄêÖÐÓжàÉÙÃë¶ø²»ÊǼÆËã³öʵ¼ÊµÄÖµ£¬ÊǸüÇåÎú¶øûÓдú¼ÛµÄ¡£
3) Òâʶµ½Õâ¸ö±í´ïʽ½«Ê¹Ò»¸ö16λ»úµÄÕûÐÍÊýÒç³ö-Òò´ËÒªÓõ½³¤ÕûÐÍ·ûºÅL,¸æËß±àÒëÆ÷Õâ¸ö³£ÊýÊǵij¤ÕûÐÍÊý¡£
4) Èç¹ûÄãÔÚÄãµÄ±í´ïʽÖÐÓõ½UL£¨±íʾÎÞ·ûºÅ³¤ÕûÐÍ£©£¬ÄÇôÄãÓÐÁËÒ»¸öºÃµÄÆðµã¡£¼Çס£¬µÚÒ»Ó¡ÏóºÜÖØÒª¡£
2 . дһ¸ö"±ê×¼"ºêMIN £¬Õâ¸öºêÊäÈëÁ½¸ö²ÎÊý²¢·µ»Ø½ÏСµÄÒ»¸ö¡£
        #define MIN(A,B) £¨£¨A£© <= (B) ? (A) : (B))
Õâ¸ö²âÊÔÊÇΪÏÂÃæµÄÄ¿µÄ¶øÉèµÄ£º
1) ±êʶ#defineÔÚºêÖÐÓ¦ÓõĻù±¾ÖªÊ¶¡£ÕâÊǺÜÖØÒªµÄ¡£ÒòΪÔÚ ......

²Ù×÷ϵͳѧϰ±Ê¼Ç(14) CºÍ»ã±àÏ໥µ÷ÓÃ

; ±àÒëÁ´½Ó·½·¨
; (ld µÄ‘-s’Ñ¡ÏîÒâΪ“strip all”)
; gcc -c not link
;
; [root@XXX XXX]# nasm -f elf foo.asm -o foo.o
; [root@XXX XXX]# gcc -c bar.c -o bar.o
; [root@XXX XXX]# ld -s foo.o bar.o -o foobar
; [root@XXX XXX]# ./foobar
; the 2nd one
; [root@XXX XXX]#
extern choose ; int choose(int a, int b);
[section .data] ; Êý¾ÝÔÚ´Ë
num1st dd 3
num2nd dd 4
[section .text] ; ´úÂëÔÚ´Ë
global _start ; ÎÒÃDZØÐëµ¼³ö _start Õâ¸öÈë¿Ú£¬ÒÔ±ãÈÃÁ´½ÓÆ÷ʶ±ð¡£
global myprint ; µ¼³öÕâ¸öº¯ÊýΪÁËÈà bar.c ʹÓÃ
_start:
push num2nd ; ©·
push num1st ; ©§
call choose ; ©Ç choose(num1st, num2nd);
add esp, 4 ; ©¿
mov ebx, 0
mov eax, 1 ; sys_exit
int 0x80 ; ϵͳµ÷ÓÃ
; void myprint(char* msg, int len)
myprint:
mov edx, [esp + 8] ; len
mov ecx, [esp + 4] ; msg
mov ebx, 1
mov eax, 4 ; sys_write
int 0x80 ; ϵͳµ÷ÓÃ
ret


void myprint(char* msg, int len);
int choose(int a, int b)
{
if(a >= b){
myprint("the 1st one\n", 13);
} ......

Linux Ï CÓïÑÔ´óÎļþ¶Áд(´óÓÚ4G£©

ÒÔϵÄ×ö·¨ÕûÀí×ÔÂÛ̳ÉϵÄÌû×Ó¡£ 
ÈçºÎcreate´óÎļþ
Òª´ó¾Í·Ç³£´ó£¬1T°É¡£
ÓÐÁ½ÖÖ·½·¨£º
 
Ò».dd
dd if=/dev/zero of=1T.img bs=1G seek=1024 count=0
bs=1G±íʾÿһ´Î¶Áд1GÊý¾Ý£¬count=0±íʾ¶Áд0´Î£¬seek=1024±íʾÂÔ¹ý1024¸öBlock²»Ð´£¬Ç°Ãæblock sizeÊÇ1G£¬ËùÒÔ¹²ÂÔ¹ý1T£¡
ÕâÊÇ´´½¨´óÐÍsparseÎļþ×î¼òµ¥µÄ·½·¨¡£
 
¶þ.ftruncate64/ftruncate
Èç¹ûÓÃϵͳº¯Êý¾ÍÉÔ΢ÓÐЩÂé·³£¬ÒòΪÉæ¼°µ½ºêµÄÎÊÌâ¡£ÎÒ»á½áºÏÒ»¸öʵ¼ÊÀý×ÓÏêϸ˵Ã÷£¬ÆäÖÐOPTION±êÖ¾µÄ¾ÍÊDzâÊÔÏî¡£
Îļþsparse.c:
 
//OPTION 1:ÊÇ·ñ¶¨ÒåÓë´óÎļþÏà¹ØµÄºê
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS 64
 
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#define FILENAME "bigfile"
#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
int main(int argc, char **argv)
{
  int fd, ret;
  off_t offset;
  int total = 0;
  if ( argc >= 2 )
  { ......

Linux Ï CÓïÑÔ´óÎļþ¶Áд(´óÓÚ4G£©

ÒÔϵÄ×ö·¨ÕûÀí×ÔÂÛ̳ÉϵÄÌû×Ó¡£ 
ÈçºÎcreate´óÎļþ
Òª´ó¾Í·Ç³£´ó£¬1T°É¡£
ÓÐÁ½ÖÖ·½·¨£º
 
Ò».dd
dd if=/dev/zero of=1T.img bs=1G seek=1024 count=0
bs=1G±íʾÿһ´Î¶Áд1GÊý¾Ý£¬count=0±íʾ¶Áд0´Î£¬seek=1024±íʾÂÔ¹ý1024¸öBlock²»Ð´£¬Ç°Ãæblock sizeÊÇ1G£¬ËùÒÔ¹²ÂÔ¹ý1T£¡
ÕâÊÇ´´½¨´óÐÍsparseÎļþ×î¼òµ¥µÄ·½·¨¡£
 
¶þ.ftruncate64/ftruncate
Èç¹ûÓÃϵͳº¯Êý¾ÍÉÔ΢ÓÐЩÂé·³£¬ÒòΪÉæ¼°µ½ºêµÄÎÊÌâ¡£ÎÒ»á½áºÏÒ»¸öʵ¼ÊÀý×ÓÏêϸ˵Ã÷£¬ÆäÖÐOPTION±êÖ¾µÄ¾ÍÊDzâÊÔÏî¡£
Îļþsparse.c:
 
//OPTION 1:ÊÇ·ñ¶¨ÒåÓë´óÎļþÏà¹ØµÄºê
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS 64
 
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#define FILENAME "bigfile"
#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
int main(int argc, char **argv)
{
  int fd, ret;
  off_t offset;
  int total = 0;
  if ( argc >= 2 )
  { ......
×ܼǼÊý:2015; ×ÜÒ³Êý:336; ÿҳ6 Ìõ; Ê×Ò³ ÉÏÒ»Ò³ [7] [8] [9] [10] 11 [12] [13] [14] [15] [16]  ÏÂÒ»Ò³ βҳ
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ