Don Burns (don_burns++at++peru.engr.sgi.com)
Fri, 25 Jun 1999 15:01:52 -0700 (PDT)
Attached (in shar):
shmem.[Ch]
derivedClass.h
p1.C
p2.C
Makefile
The base class Shmem is implemented using SVR4 shared memory, and allows
unrelated processes to share memory. It may be "black boxed" by deriving
classes from it as in derivedClass.h :
////////////////////////// derivedClass.h ////////////////////////////
#ifndef __DERIVED_CLASS_H
#define __DERIVED_CLASS_H
#include "shmem.h"
class Derived : public Shmem
{
private :
int some_integer;
public :
Derived( void ) {}
~Derived() {}
void set( int _val ) { some_integer = _val; }
int get( void ) { return some_integer; }
};
#endif
Programs p1.C and p2.C then declare a variable, passing new() a parameter
describing the name of a data pool. The data is then shared.
////////////////// p1.C //////////////////////////////
#include <unistd.h>
#include "derivedClass.h"
main( int argc, char **argv )
{
Derived *d = new ("my_datapool") Derived;
d->set( 5 );
while( d->get() == 5 )
sleep( 1 );
delete d;
}
///////////////////////// p2.C ////////////////////////////
#include <stdio.h>
#include "derivedClass.h"
main( int argc, char **argv )
{
Derived *d = new ("my_datapool") Derived;
printf( "Some Integer ; %d\n", d->get() );
d->set( 0 );
delete d;
}
/////////////////////////////////////////////////////////////////
Compile and test with :
% p1 &
% p2
There ya have it.
-don
#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 06/25/1999 22:01 UTC by don_burns++at++peru
# Source directory /DonsDisk/Work/Shmem
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 207 -rw-r--r-- ShmemExample//Makefile
# 202 -rw-r--r-- ShmemExample//p1.C
# 208 -rw-r--r-- ShmemExample//p2.C
# 1409 -rw-r--r-- ShmemExample//shmem.C
# 276 -rw-r--r-- ShmemExample//shmem.h
# 291 -rw-r--r-- ShmemExample//derivedClass.h
#
# ============= ShmemExample//Makefile ==============
if test ! -d 'ShmemExample'; then
echo 'x - creating directory ShmemExample'
mkdir 'ShmemExample'
fi
if test -f 'ShmemExample//Makefile' -a X"$1" != X"-c"; then
echo 'x - skipping ShmemExample//Makefile (File already exists)'
else
echo 'x - extracting ShmemExample//Makefile (Compressed)'
sed 's/^X//' << 'SHAR_EOF' | uudecode &&
begin 600 _shar_cmp_.tmp
M'YV,(T+,:1-F31D%"J#$>")$R100/4#`B>'B#8++at++Y:-J4:5,QH0R&#B%*E%'Q
M8L:-'14,6;'""),++at++1QY&;'$&1`LW,V0H8$+$)<R'(FG:Q*E301++at++V;$#HD!AC
M),*)2D&00*$0Y)04"A),7;DBA504/'W&]#JU:L.K-BV2`/)41M2R'\]BU8J"
0*UFP/5^._0HEKD.O+=2R!;DB
`
end
SHAR_EOF
echo 'uncompressing file ShmemExample//Makefile' &&
compress -d < _shar_cmp_.tmp > 'ShmemExample//Makefile' && rm -f _shar_cmp_.tmp &&
chmod 0644 ShmemExample//Makefile ||
echo 'restore of ShmemExample//Makefile failed'
Wc_c="`wc -c < 'ShmemExample//Makefile'`"
test 207 -eq "$Wc_c" ||
echo 'ShmemExample//Makefile: original size 207, current size' "$Wc_c"
fi
# ============= ShmemExample//p1.C ==============
if test -f 'ShmemExample//p1.C' -a X"$1" != X"-c"; then
echo 'x - skipping ShmemExample//p1.C (File already exists)'
else
echo 'x - extracting ShmemExample//p1.C (Compressed)'
sed 's/^X//' << 'SHAR_EOF' | uudecode &&
begin 600 _shar_cmp_.tmp
M'YV,(]*X&<.F#IDR('C4<9-F#ATR+M#X4!!P8,&#($0<E)/&3ADR0]B$F3,G
MH++at++++at++%*-N$$8++at++"A$`Z(,+(.3.&!8++at++Q:&2"4*%"YAD[(%(HV*,`A%$01,IP]$AF
M9],>(-R4N0,"A8++at++V>;Z0"4,G#)PW;]B(2(%4:<>/.U`>!4&FA8\Y9>BTK!$T
J;=&C=]"D85.F95L?9^*B(-L#*EVA">;P+0.G98RZ:H\>Y$L'(9FT?10`
`
end
SHAR_EOF
echo 'uncompressing file ShmemExample//p1.C' &&
compress -d < _shar_cmp_.tmp > 'ShmemExample//p1.C' && rm -f _shar_cmp_.tmp &&
chmod 0644 ShmemExample//p1.C ||
echo 'restore of ShmemExample//p1.C failed'
Wc_c="`wc -c < 'ShmemExample//p1.C'`"
test 202 -eq "$Wc_c" ||
echo 'ShmemExample//p1.C: original size 202, current size' "$Wc_c"
fi
# ============= ShmemExample//p2.C ==============
if test -f 'ShmemExample//p2.C' -a X"$1" != X"-c"; then
echo 'x - skipping ShmemExample//p2.C (File already exists)'
else
echo 'x - extracting ShmemExample//p2.C (Compressed)'
sed 's/^X//' << 'SHAR_EOF' | uudecode &&
begin 600 _shar_cmp_.tmp
M'YV,(]*X&<.F#IDR('C,H4,FS1L7:'PH"#BPX$$0(++at++[*26.G#)DA;,+,F0-1
MA(*3;<((1`%"(!T08>2<&<,"Q!++at++T,4&H4!'SC!T0*13L40"B*`++at++B939V)*.3
M:0\0;LK<`8%"1)L\7\B$H1,&SILW;$2D.)J4H\<=)XV"++at+++/1#1TS+$5,>=,&
M81*W9<XD!;$#1`DR7-R(J$FFA0^]=%",38&6J-'"/N:420P"!M#&:++at++^RF8R0
%#-H^"++at++`D
`
end
SHAR_EOF
echo 'uncompressing file ShmemExample//p2.C' &&
compress -d < _shar_cmp_.tmp > 'ShmemExample//p2.C' && rm -f _shar_cmp_.tmp &&
chmod 0644 ShmemExample//p2.C ||
echo 'restore of ShmemExample//p2.C failed'
Wc_c="`wc -c < 'ShmemExample//p2.C'`"
test 208 -eq "$Wc_c" ||
echo 'ShmemExample//p2.C: original size 208, current size' "$Wc_c"
fi
# ============= ShmemExample//shmem.C ==============
if test -f 'ShmemExample//shmem.C' -a X"$1" != X"-c"; then
echo 'x - skipping ShmemExample//shmem.C (File already exists)'
else
echo 'x - extracting ShmemExample//shmem.C (Compressed)'
sed 's/^X//' << 'SHAR_EOF' | uudecode &&
begin 600 _shar_cmp_.tmp
M'YV,(]*X&<.F#IDR('C4<9-F#ATR+M#X4!!P8,&#"1V22?,FXL2*!`TBY&%F
MC!LZ;#Q2%!++at++2(X\Y>>:\F(.FC<J5%D6"$$&S31F;:$0H4&#G31HR(%1,J?E3
MAXXW<,K("4/GC1P0;LK<00%B3AH]9;[0Z?JU#`L08]ZX<8++at++639BK*M:4R>,F
MC$\0*13L40"B;]NW(.!01;-%1++at++T;77;P]3O&[=6?<\YLB2$#1^+%?06.E9M'
ML5\0FKO6/.K9;V++at++S9!1C[++at++I'CF8S7`7307-6Q`LZ;>"\*#%'Q%G.=>^F*)T9
M-++at++++at++4J$'T``&UC)O8++at++\\^^3)$2I$++at++5,["L,$=;XJ$(&#++at++7;WW\^<YK5]SA7RF
M-A6G6;?R3N$;!'"["(<K2!!5CARKZ[41&5Z*)2!'&734(8<;QQ5U5%(IP,`$
M<2#T,=1J:1B'`F?*++at++6!&56M`-YMVWH$G7EZ?E6=>7^BY=I)Q[+D'GU8HS%??
M?<(5V-]_<++at++0XH'X&(J++at++++at++++at++R++at++XB)0*$4ZXFH6K$?3&'&5PE9Q^0WV6(5<H]/3++at++
M<CV=++at++2!7G)WE%5AG)0'%$-19AQT(?(3'G0TE\A#>>"GNUQA++at++[$U6V64)M*++at++>
M"#'N])X.\=4X!WV_S15<?CI*Q:./9Q"XWX$)+MB++at++44<F22&3GRWE4QM)C;4<
M"I[^!&%/5'&E)1G:,7'6%$++at++T\8443A`A*8;&T=&"#ZN"$`*7HR&%XHH++at++Z,IK
ML!VN2N&57=&QX!BY<67LHHG2A=^KL18AJQ-!-%'$%U,DH441(+0`0++at++QXT4FL
M0\_"D8>TNU)KGZ+7++at++++at++"KM]MV^VVXXY9[KJ2?38O?%O=J^P6WWH(K+KGFQM!%
MAS"H]AFE0Q:K&).EMN%4QEP9.9Z*?=5%!QUA-.;327.LL,+%0V7LE!\<++at++^!Q
M7B"7VX+())OL'!US2&R:<3B7S!3*"2UW(GFK66E<K[^6B^ZP*]9,+&A+US0&
M2JH&6^:9LS:1A*W?R7GTU%/O".!./5W-A++at++++at++`$\MD`G=>)1MAAB%6H)\OBDC;
H3K?EMEMO9RTJ:0+,+L2&0"$&-EBZ8H^7P&=F][B3X8BSK=]G%C*I`)\O
`
end
SHAR_EOF
echo 'uncompressing file ShmemExample//shmem.C' &&
compress -d < _shar_cmp_.tmp > 'ShmemExample//shmem.C' && rm -f _shar_cmp_.tmp &&
chmod 0644 ShmemExample//shmem.C ||
echo 'restore of ShmemExample//shmem.C failed'
Wc_c="`wc -c < 'ShmemExample//shmem.C'`"
test 1409 -eq "$Wc_c" ||
echo 'ShmemExample//shmem.C: original size 1409, current size' "$Wc_c"
fi
# ============= ShmemExample//shmem.h ==============
if test -f 'ShmemExample//shmem.h' -a X"$1" != X"-c"; then
echo 'x - skipping ShmemExample//shmem.h (File already exists)'
else
echo 'x - extracting ShmemExample//shmem.h (Compressed)'
sed 's/^X//' << 'SHAR_EOF' | uudecode &&
begin 600 _shar_cmp_.tmp
M'YV,(]*8<4.FC!D07[Y,0=*D2),O2!2,*&++at++FC9LR"!4R=`A1++at++42+8]C4*0B"
M1YLP;-B\&>,"C0^/$PU:Q+BPX4,G01HJ3**E2((9,CR&##-G#H++at++I:-J4:0-B
MCP(04$'`D9/&3A++at++Z&'4H2#`&31++at++Y(-R$4;JE)D><.J?P+-)EQU:+=$#,29J&
MC-L$<,->I1.FJU(W=.:XC2JUCA++at++V:<:`T)H`J=(V*$#8>5,71(J[?APOC3RY
M\N6MG<F`4/$&3ADY5]^`O7++at++G\IPT>LI\H<,"Q)++at++W;N;$[?IUM&6W?=Q*+$-0
"H`*M
`
end
SHAR_EOF
echo 'uncompressing file ShmemExample//shmem.h' &&
compress -d < _shar_cmp_.tmp > 'ShmemExample//shmem.h' && rm -f _shar_cmp_.tmp &&
chmod 0644 ShmemExample//shmem.h ||
echo 'restore of ShmemExample//shmem.h failed'
Wc_c="`wc -c < 'ShmemExample//shmem.h'`"
test 276 -eq "$Wc_c" ||
echo 'ShmemExample//shmem.h: original size 276, current size' "$Wc_c"
fi
# ============= ShmemExample//derivedClass.h ==============
if test -f 'ShmemExample//derivedClass.h' -a X"$1" != X"-c"; then
echo 'x - skipping ShmemExample//derivedClass.h (File already exists)'
else
echo 'x - extracting ShmemExample//derivedClass.h (Compressed)'
sed 's/^X//' << 'SHAR_EOF' | uudecode &&
begin 600 _shar_cmp_.tmp
M'YV,(]*8<4.FC!D07[X0*2(EB94B1+X,81)DRI0O2!2,*&++at++FC9LR"!4R=`A1
M(D6+&!6H#.AF#)LZ!4&(F(.F39DV+M"(4*G`99++at++Y<T`0*2,GC9TR9$#H``&G
MCA++at++V:<:`F%+SIH(]"D!H95K43A++at++Z('4H2."1#H++at++Y;VQ^*5OF#-$=*K<R=0I5
MJM++at++$0[LB10'"SILT25.`V--GK)^\1O<*)JPR++at++5_`9\O0X5L6H5<V(!:?35MF
MK1NP;N6`Z&$Y#)L=(`J3_:S5[>2^?P,/!B%'<ATY;C:K91L:=1\0"OK`U5B&
#H$`%
`
end
SHAR_EOF
echo 'uncompressing file ShmemExample//derivedClass.h' &&
compress -d < _shar_cmp_.tmp > 'ShmemExample//derivedClass.h' && rm -f _shar_cmp_.tmp &&
chmod 0644 ShmemExample//derivedClass.h ||
echo 'restore of ShmemExample//derivedClass.h failed'
Wc_c="`wc -c < 'ShmemExample//derivedClass.h'`"
test 291 -eq "$Wc_c" ||
echo 'ShmemExample//derivedClass.h: original size 291, current size' "$Wc_c"
fi
exit 0
This archive was generated by hypermail 2.0b2 on Fri Jun 25 1999 - 15:01:58 PDT