其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
Linux中pascal与c的数据交换

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

Linuxpascalc的数据交换

方法:
         通信机制通过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
 
补充:
         针对这一点。我们对于shared memory要注意安排,内存块的利用。通过对内存快共享利用。做到及时的沟通pascal和c程序在linux的沟通。
 
建议:
Shared Memory的充分利用:
提升:定义好与内存块表格结构体。必须要有一个限制机制使得大家知道有数据要发送。以及接收。也就是这个表格中。要分不同的区域。 并且提供统一的。存取。发送。控制函数。
 
Linux中c代码示例

#include <stdio.h>

#include <unistd.h>

#include <sys/types.h>

#include <sys/ipc.h>

#include <sys/shm.h>

#include <errno.h>

#include <stdlib.h>

 

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)\n",

                           key, size, perm,getpid());

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

  }

 else

 {

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

 

 }

 

//***

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

 {

       printf("shmat pas OK\n");

 }

 printf("setting addr to 123\n");

 *addr = 123;

 

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

 sleep(50);

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

 {

        printf("shmctl pas OK \n");                    

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

 }

 else

 {

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

 }

}

 




相关文章

相关软件