ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Linux中pascal与c的数据交换 (转)

Linux中pascal与c的数据交换 (转)

原创 Linux操作系统 作者:WebSnap 时间:2019-06-19 18:00:05 0 删除 编辑
Linux中pascal与c的数据交换 (转)

中pascal与c的数据

方法:


  通信机制通过shared memory的存取,到达ipc.


环境的限制:


  本开发7.1中Shared Memory的限制:


------ Shared Memory Limits --------


max number of segments = 4096


max seg size (kbytes) = 32768


max total shared memory (kbytes) = 8388608


min seg size (bytes) = 1


 :namespace prefix = o ns = "urn:schemas--com::office" />


补充:


  针对这一点。我们对于shared memory要注意安排,块的利用。通过对内存快共享利用。做到及时的沟通pascal和c在linux的沟通。


 


建议:


Shared Memory的充分利用:


提升:定义好与内存块表格结构体。必须要有一个限制机制使得大家知道有数据要发送。以及接收。也就是这个表格中。要分不同的区域。 并且提供统一的。存取。发送。控制。


 


Linux中c代码示例


#include

#include

#include

#include

#include

#include

#include

 

main()

{

  int id, ret;

  int size;

  int pe= 0666;

  key_t key ;

  char *addr;

  struct shmid_ds  buf ;

 

 key = 1126;  //注意此处是要和kylix系统中的key一致,这样才能与其共享

 size = 6553;

 

 if ((id=shmget(key, size, IPC_CREAT | perm))== -1) //***

 {

  printf("shmget (key:0x%x,size:%d,perm:0x%x. pid:%ld) ",

    key, size, perm,getpid());

  printf("errno = %d ", errno);

  }

 else

 {

  printf("id = %d ", id);

 

 }

 

//***

 if ((addr = (char *)shmat(id, (char *)NULL, NULL)) == (char *)-1)

 {

  printf("shmat pas OK ");

 }

 printf("setting addr to 123 ");

 *addr = 123;

 

 printf("addr = %x %d ", addr, *addr);

 sleep(50);

 if ((ret=shmctl(id, IPC_D, NULL))== -1)  //***

 {

  printf("shmctl pas OK "); 

  printf("errno = %d ", errno);

 }

 else

 {

  printf("ret = %d ", ret);

 }

}

 


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10797429/viewspace-101645/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-01-04

  • 博文量
    175
  • 访问量
    141717