tags:

views:

47

answers:

2

In c you can do

shmid = shmget(SHMEM_KEY, sizeof(int*) * n , SHEMEM_MODE | IPC_CREAT);
int* shmem = shmat(shmid, NULL, 0);

to assign first given free memory space as a shared memory.

Is there any way to assigne current memory space as a shared memory?

+1  A: 

You use shmat() to alias the shared memory you created to any arbitrary page-aligned range in your address-space

So this isn't taking some memory you already have and publishing it; its taking some new shared memory, you then copy what you want to publish across, then use shmat to alias it to where you had what you wanted to publish - this has the same effect.

Will
well there you go.
Alexander Rafferty
I'm not very clear, could you possibly disambiguate by actual syntax?
Ankiov Spetsnaz
A: 

First I would advise not to use the oldish shmget interfaces but the more modern POSIX interfaces shm_open and mmap (if you have them, you didn't specify your system)

Then the mmap allows you to propose an address in your address space where you'd like to have the segment

this is not exactly what you are asking for, but the closest you can get, I think

Jens Gustedt