System: Sun SPARC
We need to transfer data from one program (a simulation) to another
(a graphic program). Up to now, we used a simple file to do that.
Of course we wanted to speed up things a little bit, so we decided
to use shared memory.
To test this, we wrote 2 little programs, one for writing, one for reading.
The procedure to read the contents could be (writing looks similar):
tmp = start = (double *)shmat(shmname,0,1); /* make shm accessable */
n = (int)(*tmp++); /* # of value pairs */
for ( ; n > 0; n--)
m1 = *tmp++; /* just reading dummies */
m2 = *tmp++;
This works fine (and fast).Quote:}
In a Sun document named "Porting Software to SPARC Systems"
(from the "Programmer's Language Guides"), chapter 2, you
can read the following :
On SPARC machines, all quantities must be aligned on
boundaries corresponding to their sizes: bytes on byte
boundaries, (16-bit) halfwords on halfword boundaries,
There are several C language constructs, however, that
may lead to a bus error during execution:
- Casting a pointer to a char or unsigned char into
a pointer to a larger quantity, such as ...[deleted]...
shmat() returns a char *. Is there any way to make sure,
that it points to a suitable boundary for a double?
Is it a good idea to control the read/write access via
IPC-Queues (the 'writer' waits until the 'reader' says ok)?
Are there any examples for such a communication?
Thanks in advance,
Institut fuer Chemische Verfahrenstechnik
Boeblinger Str. 72
D-7000 Stuttgart 1