1 " |
1 " |
2 COPYRIGHT (c) 1994 by Claus Gittinger |
2 COPYRIGHT (c) 1994 by Claus Gittinger |
3 All Rights Reserved |
3 All Rights Reserved |
4 |
4 |
5 This software is furnished under a license and may be used |
5 This software is furnished under a license and may be used |
6 only in accordance with the terms of that license and with the |
6 only in accordance with the terms of that license and with the |
7 inclusion of the above copyright notice. This software may not |
7 inclusion of the above copyright notice. This software may not |
8 be provided or otherwise made available to, or used by, any |
8 be provided or otherwise made available to, or used by, any |
9 other person. No title to or ownership of the software is |
9 other person. No title to or ownership of the software is |
10 hereby transferred. |
10 hereby transferred. |
11 " |
11 " |
12 |
12 |
13 Message subclass:#MessageSend |
13 Message subclass:#MessageSend |
14 instanceVariableNames:'receiver' |
14 instanceVariableNames:'receiver' |
15 classVariableNames:'' |
15 classVariableNames:'' |
16 poolDictionaries:'' |
16 poolDictionaries:'' |
17 category:'Kernel-Methods' |
17 category:'Kernel-Methods' |
18 ! |
18 ! |
19 |
19 |
20 MessageSend comment:' |
20 MessageSend comment:' |
21 COPYRIGHT (c) 1994 by Claus Gittinger |
21 COPYRIGHT (c) 1994 by Claus Gittinger |
22 All Rights Reserved |
22 All Rights Reserved |
23 |
23 |
24 $Header: /cvs/stx/stx/libbasic/MessageSend.st,v 1.2 1994-10-10 00:53:52 claus Exp $ |
24 $Header: /cvs/stx/stx/libbasic/MessageSend.st,v 1.3 1995-05-12 12:35:09 claus Exp $ |
25 '! |
25 '! |
26 |
26 |
27 !MessageSend class methodsFor:'documentation'! |
27 !MessageSend class methodsFor:'documentation'! |
28 |
28 |
29 copyright |
29 copyright |
30 " |
30 " |
31 COPYRIGHT (c) 1994 by Claus Gittinger |
31 COPYRIGHT (c) 1994 by Claus Gittinger |
32 All Rights Reserved |
32 All Rights Reserved |
33 |
33 |
34 This software is furnished under a license and may be used |
34 This software is furnished under a license and may be used |
35 only in accordance with the terms of that license and with the |
35 only in accordance with the terms of that license and with the |
36 inclusion of the above copyright notice. This software may not |
36 inclusion of the above copyright notice. This software may not |
37 be provided or otherwise made available to, or used by, any |
37 be provided or otherwise made available to, or used by, any |
52 They keep some receiver, selector and arguments and can be evaluated |
52 They keep some receiver, selector and arguments and can be evaluated |
53 at any time later. |
53 at any time later. |
54 They can also be used as replacement for simple [self foo]-blocks. |
54 They can also be used as replacement for simple [self foo]-blocks. |
55 Of course, they could also be replaced by blocks such as |
55 Of course, they could also be replaced by blocks such as |
56 '[receiver perform:selector withArguments:arguments]', |
56 '[receiver perform:selector withArguments:arguments]', |
57 but blocks are somewhat more expensive in their creation and use. |
57 but blocks are somewhat more expensive in their creation and require |
|
58 more storage. |
|
59 |
58 However, the send-operation itself is faster in a block, since it |
60 However, the send-operation itself is faster in a block, since it |
59 will use a better caching scheme (inline-cache) for its send, while |
61 will use a better caching scheme (inline-cache) for its send, while |
60 sending here is done with a #perform:, which is not inline-cached. |
62 sending here is done with a #perform:, which is not inline-cached. |
61 Thus it is not sure, which one is faster in the end ... |
63 Thus it is not sure, which one is faster in the end ... |
|
64 |
|
65 If you plan to write a simulator and want to queue cillions of blocks, |
|
66 try to use MessageSends (or even: message); this will save you a lot memory. |
62 |
67 |
63 Example: |
68 Example: |
64 |
69 |
65 |m| |
70 |m| |
66 |
71 |
67 m := MessageSend receiver:1 selector:#+ arguments:#(2). |
72 m := MessageSend receiver:1 selector:#+ arguments:#(2). |
68 m value. |
73 m value. |
69 |
74 |
|
75 is almost the same as: |
|
76 |
|
77 |m| |
|
78 |
|
79 m := [1+2]. |
|
80 m value. |
|
81 |
|
82 |
70 Example2 (a simulation) |
83 Example2 (a simulation) |
71 |q| |
84 |q| |
72 |
85 |
73 q := Queue new. |
86 q := Queue new. |
74 ... |
87 ... |
75 'put some action into the queue' |
88 'put some action into the queue' |
76 q nextPut:(MessageSend receiver:something selector:#foo arguments:#(). |
89 q nextPut:(MessageSend receiver:someone selector:#foo arguments:#(). |
77 ... |
90 ... |
78 'evaluate next action from the queue' |
91 'evaluate next action from the queue' |
79 q next value |
92 q next value |
|
93 ... |
|
94 |
|
95 if all sends are going to the same receiver, use: |
|
96 |q| |
|
97 |
|
98 q := Queue new. |
|
99 ... |
|
100 'put some action into the queue' |
|
101 q nextPut:(Message selector:#foo arguments:#(). |
|
102 ... |
|
103 'evaluate next action from the queue' |
|
104 q next sendTo:someone |
80 ... |
105 ... |
81 " |
106 " |
82 ! ! |
107 ! ! |
83 |
108 |
84 !MessageSend class methodsFor:'instance creation'! |
109 !MessageSend class methodsFor:'instance creation'! |
85 |
110 |
86 receiver:r selector:sel arguments:argArray |
111 receiver:r selector:sel arguments:argArray |
87 |newMessage| |
112 |newMessage| |
88 |
113 |
89 newMessage := super setSelector:sel arguments:argArray. |
114 newMessage := super new setSelector:sel arguments:argArray. |
90 newMessage receiver:r. |
115 newMessage receiver:r. |
91 ^ newMessage |
116 ^ newMessage |
92 ! ! |
117 ! ! |
93 |
118 |
94 !MessageSend methodsFor:'evaluation'! |
119 !MessageSend methodsFor:'evaluation'! |