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

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

Linux中pascal与c的数据交换

方法:

 
 

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

 
 

环境的限制:

 
 

  本开发系统redhat7.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

 
 

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

 
 

补充:

 
 

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

 
 

 

 
 

建议:

 
 

Shared Memory的充分利用:

 
 

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

 
 

 

 
 

Linux中c代码示例

 
 

#include

#include

#include

#include

#include

#include

#include

 

main()

{

  int id, ret;

  int size;

  int peRM = 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_RmiD, NULL))== -1)  //***

 {

  printf("shmctl pas OK "); 

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

 }

 else

 {

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

 }

}

 


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

转载于:http://blog.itpub.net/10797429/viewspace-101645/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值