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 补充: 针对这一点。我们对于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);
}
}
[Delphi程序]Object Pascal:从对象指针谈起 [Delphi程序]浅谈Object Pascal的指针 [Delphi程序]kmp模式匹配算法的pascal实现 [Delphi程序]Object Pascal Style Guide [Delphi程序]Pascal 精要--第一章 [Delphi程序]Object Pascal中String类型的内幕探讨 [Delphi程序]Why Pascal is Not My Favourite Programming Lan… [Delphi程序]delphi学习笔记(2)-object pascal语言的语句 [Delphi程序]delphi学习笔记(1)-object pascal语言的数据类… [Delphi程序]Ojbect Pascal动态数组浅说
|