Jan E. Schotsman wrote:
> Hello all,
>
> If you're not on the beach maybe you can give me a little help.
> I need to implement shared memory between my application and a helper
> tool.
> At first I tried CFMessageProts. This works, but if you transport huge
> amounts of data the data get all paged out and after a few GB I crash.
> Then I tred shmget and friends. This works, but I can get only 1-2 MB of
> memory this way. I need at least 8MB and I would prefer no limit atall.
> So now I am trying mapping a file but I can't get this to work.
> The following bare-bones XCode Carbon application crashes. Please tell
> me what is wrong.
>
> Jan.
>
>
As for the shmget and shmat services, did you use the sysctl command to
check the maximums set for the kernel.
Check the output of: sysctl -a | grep shm
the kern.sysv.shmmax parameter is the maximum size of a segment.
The following code tests the shm services - pass the size on the command
line:
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <errno.h>
#include <stdio.h>
int main(int argc, char** argv)
{
int key = 0x1000;
int id;
void* sharedmem;
if(argc != 2)
{
printf("Usage: shmtest <size>\n");
return 0;
}
int size = atoi(argv[1]);
if(size <= 0)
{
printf("Invalid size: %d\n", size);
return 0;
}
id = shmget(key, size, IPC_CREAT|SHM_R|SHM_W);
if(key > 0)
{
sharedmem = shmat(id, 0, 0);
if(sharedmem != (void*)-1)
{
printf("Success\n");
shmdt(sharedmem);
}
else
{
printf("Failed shmat - %d\n", errno);
}
shmctl(id, IPC_RMID, 0);
}
else
{
printf("Failed shmget - %d\n", errno);
}
return 0;
}
>> Stay informed about: Shared memory