With 2 c files, they use 1 memory area. How to set limit memory for them ???
I use library shm.h and its func (shmget, shmat, shmctl ... ). When i share memory for another, i don't know how to limit the memory ???
With 2 c files, they use 1 memory area. How to set limit memory for them ???
I use library shm.h and its func (shmget, shmat, shmctl ... ). When i share memory for another, i don't know how to limit the memory ???
Size of segment :
Code:#define SHMSZ 27When SHMSZ > 27.Code:if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) { perror("shmget"); exit(1); }
Why ?Code:shmget: Invalid argument
It's implementation-specific. Have you looked at the man page?
On my system it says:
Is this your first shmget() call with that key?Code:SHMMAX Maximum size in bytes for a shared memory seg­ ment: implementation dependent (currently 4M). SHMMIN Minimum size in bytes for a shared memory seg­ ment: implementation dependent (currently 1 byte, though PAGE_SIZE is the effective minimum size).
Code:EINVAL if a new segment was to be created and size < SHMMIN or size > SHMMAX, or no new segment was to be created, a segment with given key existed, but size is greater than the size of that segment.
Last edited by itsme86; 09-06-2006 at 10:25 PM.
If you understand what you're doing, you're not learning anything.
I use FreeBSD 6.0
The man page do not show that.
Maybe not, but it does say this:And this:When creating a new shared memory segment, size indicates the desired
size of the new segment in bytes. The size of the segment may be rounded
up to a multiple convenient to the kernel (i.e., the page size).Quzah.ERRORS
The shmget() system call will fail if:
[EINVAL]Size specified is greater than the size of the previ-
ously existing segment. Size specified is less than
the system imposed minimum, or greater than the system
imposed maximum.
Hope is the first step on the road to disappointment.
Thanks so much.
Because I use it but not remove it after run. So I change the seg size and compile, it occurs error.
I have solved it.
Can I write one struct to share memory ??
I insert it 10 times in loop. And then insert 1 time with this memory. It replace the first record in share memory ??? How can I add it in the end of the share memory ???Code:struct test { int a; int b; }
Code:MEM Before : {0,0} {1,1} {2,2} {3,3} {4,4} {5,5} {6,6} {7,7} {8,8} {9,9} After insert {10, 10} MEM after : {10,10} {1,1} {2,2} {3,3} {4,4} {5,5} {6,6} {7,7} {8,8} {9,9} Can add the end of shared memory to have this result : {0,0} {1,1} {2,2} {3,3} {4,4} {5,5} {6,6} {7,7} {8,8} {9,9} {10,10} ???