Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ÔÚC#Àï´´½¨ºÍʹÓÃC·ç¸ñÊý¾Ý½á¹¹

ÔÚC#Àï´´½¨ºÍʹÓÃC·ç¸ñÊý¾Ý½á¹¹£¬¼´·ÇÍйܵÄÊý¾Ý½á¹¹£¬¿ÉÒÔÌá¸ßÐÔÄÜ¡£
1 Êý¾Ý½á¹¹µÄ¶¨Òå
¿´ÏÂÃæÀý×Ó£º
    unsafe struct A {
        public int x;
    }
    unsafe struct B {
        public A a; //AÄÚǶµ½BÖÐ
        public A* pa; //AÁ´½Óµ½BÖÐ
        public fixed int x[10]; //¹Ì¶¨´óСµÄÊý×éÄÚǶµ½BÖÐ
        public int* p; //´óС䶨µÄÊý×飨Ê×Ö¸Õ룩Á´½Óµ½BÖÐ
    }
ËùÓÐÊý¾Ý½á¹¹£¬¶¼ÓÃstruct£¬²»ÓÃclass£¬¶øÇÒstructÿһ¸ö×ÓÔªËض¼²»ÄÜÊÇclass¡£
2 ÔÚ·ÇÍйܶÑÖд´½¨¶ÔÏó»òÊý×é
¿´ÏÂÃæÀý×Ó£¨¾²Ì¬Ààclass CµÄÔ´´úÂëÔÚºóÃæ¸ø³ö£©£º
    A* pa=(A*)C.New(sizeof(A)); //Ï൱ÓÚCÀïÃæµÄA* pa=(A*)malloc(sizeof(A));
    B* pb=(B*)C.New(sizeof(B),5); //´´½¨Ò»¸öÓÐ5¸öÔªËصÄһάBÊý×é
    int** a1=(int**)C.New(sizeof(int), 2, 3); //´´½¨Ò»¸ö2*3¶þάintÊý×é,¿ÉÓÃa1[i][j]·ÃÎÊÿ¸öÔªËØ
    int** a2=(int**)C.New(new int[2,3]); //¹¦ÄÜͬÉÏ,²¢ÓÃ0³õʼ»¯Êý×é
    int** a3=(int**)C.New(new int[,]{{1, 2, 3},{4, 5, 6}}); //¹¦ÄÜͬÉÏ,²¢ÓÃÖ¸¶¨Öµ³õʼ»¯Êý×é
    char* s=C.New("abcde"); //ÓÃ×Ö·û´®³õʼ»¯charÊý×é
    C.Delete(pa, pb, a1, a2, a3, s); //ÊÍ·ÅÉÏÊö¶ÔÏóµÄÄÚ´æ,²ÎÊý¸öÊýÈÎÒâ
3 ÔÚÕ»Öд´½¨¶ÔÏó»òÊý×é
¿´ÏÂÃæÀý×Ó:
    A a; //½¨Á¢Õ»¶ÔÏóa
    B* pb=stackalloc B[5]; //´´½¨Ò»¸öÓÐ5¸öÔªËصÄһάջÊý×é
    char* p1=stackalloc char[5];
    C.Copy(p1, "Test"); //°Ñ×Ö·û´®ÀïµÄ×Ö·û¸´ÖƵ½Õ»Êý×éÀï
    C.Copy(p1, new[] { 'T', 'e', 's', 't', '\0' }); //°ÑÍйÜÊý×éµÄÊý¾Ý¸´ÖƵ½Õ»Êý×éÀï
4 ¾²Ì¬Ààclass CµÄÔ´´úÂë
unsafe static class C {
[DllImport("msvcrt")]
public static extern void* malloc(uint size);
[DllImport("msvcrt")]
public static extern void* realloc(void* p, uint newsize);
[DllImpor


Ïà¹ØÎĵµ£º

c/s½á¹¹

¡¡¡¡ÔÚÍøÂçÁ¬½ÓģʽÖÐ,³ý¶ÔµÈÍøÍâ,»¹ÓÐÁíÒ»ÖÖÐÎʽµÄÍøÂ磬¼´¿Í»§»ú/·þÎñÆ÷Íø£¬Client/Server¡£ÔÚ¿Í»§»ú/·þÎñÆ÷ÍøÂçÖУ¬·þÎñÆ÷ÊÇÍøÂçµÄºËÐÄ£¬¶ø¿Í»§»úÊÇÍøÂçµÄ»ù´¡£¬¿Í»§»úÒÀ¿¿·þÎñÆ÷»ñµÃËùÐèÒªµÄÍøÂç×ÊÔ´£¬¶ø·þÎñÆ÷Ϊ¿Í»§»úÌṩÍøÂç±ØÐëµÄ×ÊÔ´¡£
¡¡¡¡ÕâÀï¿Í»§ºÍ·þÎñÆ÷¶¼ÊÇָͨÐÅÖÐËùÉæ¼°µÄÁ½¸öÓ¦Óýø³Ì£¨Èí¼þ£©¡£Ê¹ÓüÆËã» ......

50¸öc/c++Ô´´úÂëÍøÕ¾

C/C++ÊÇ×îÖ÷ÒªµÄ±à³ÌÓïÑÔ¡£ÕâÀïÁгöÁË50ÃûÓÅÐãÍøÕ¾ºÍÍøÒ³Çåµ¥£¬ÕâЩÍøÕ¾Ìṩc/c++Ô´´úÂë ¡£Õâ·ÝÇåµ¥ÌṩÁËÔ´´úÂëµÄÁ´½ÓÒÔ¼°ËüÃǵÄС˵Ã÷¡£ÎÒÒѾ¡Á¦°üÀ¨×î¼ÑµÄC/C++Ô´´úÂëµÄÍøÕ¾¡£Õâ²»ÊÇÒ»¸öÍêÕûµÄÇåµ¥£¬ÄúÓн¨Òé¿ÉÒÔÁªÏµÎÒ£¬ÎÒ½«»¶Ó­ÄúµÄ½¨ Ò飬ÒÔ½øÒ»²½¼ÓÇ¿Õâ·½ÃæµÄÇåµ¥¡£ 
1¡¢http://snippets.dzone.com/tag/c/&nbs ......

c°æµÄ»Øµ÷º¯ÊýÓëc++°æµÄÐ麯Êý

CÓïÑԵĻص÷º¯Êý˼Ïë´úÂ룺
#include <stdio.h>
void *max(void *base, unsigned int nmemb, unsigned int size,
    int (*compar)(const void *, const void *))
{
    int i;
    void* max_data = base;
    char* tmp = base;
 &nbs ......

extern "C"

Èç¹ûC++µ÷ÓÃÒ»¸öCÓïÑÔ±àдµÄ.DLLʱ£¬µ±°üÀ¨.DLLµÄÍ·Îļþ»òÉùÃ÷½Ó¿Úº¯Êýʱ£¬Ó¦¼Óextern "C" {¡¡}¡£
È磺
Í·ÎļþcExample.h
#include <stdio.h>
#ifndef C_EXAMPLE_H
#define C_EXAMPLE_H
int add(int x,int y);
#endif

º¯ÊýʵÏÖÎļþcExample.c(×¢ÒâÊÇ.cÎļþ)
#include<stdio.h>
#include "cExample ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ