52 [author:] |
54 [author:] |
53 Claus Gittinger |
55 Claus Gittinger |
54 " |
56 " |
55 ! ! |
57 ! ! |
56 |
58 |
57 |
|
58 |
|
59 !FloatArray class methodsFor:'queries'! |
59 !FloatArray class methodsFor:'queries'! |
60 |
60 |
61 elementByteSize |
61 elementByteSize |
62 "for bit-like containers, return the number of bytes stored per element. |
62 "for bit-like containers, return the number of bytes stored per element. |
63 Here, 4 is returned" |
63 Here, 4 is returned" |
64 |
64 |
65 ^ 4 |
65 ^ 4 |
66 |
66 |
67 "Created: / 15-09-2011 / 14:12:39 / cg" |
67 "Created: / 15-09-2011 / 14:12:39 / cg" |
68 ! ! |
68 ! ! |
69 |
|
70 |
69 |
71 !FloatArray methodsFor:'copying'! |
70 !FloatArray methodsFor:'copying'! |
72 |
71 |
73 clone |
72 clone |
74 "return a copy of the receiver" |
73 "return a copy of the receiver" |
117 OBJ __nObj; |
116 OBJ __nObj; |
118 int nBytes; |
117 int nBytes; |
119 |
118 |
120 // don't do this; sizeof returns the padded size! |
119 // don't do this; sizeof returns the padded size! |
121 // nBytes = sizeof(struct __FloatArray) + (__n - 1) * sizeof(float); |
120 // nBytes = sizeof(struct __FloatArray) + (__n - 1) * sizeof(float); |
122 nBytes = OHDR_SIZE + (__n * sizeof(float)); |
121 /* and what is the disadvantage of having the padded size? |
123 |
122 in an 32 bit enviroments, we do need the padded size, |
|
123 otherwise there are to less bytes allocated */ |
|
124 // nBytes = OHDR_SIZE + (__n * sizeof(float)); |
|
125 |
|
126 nBytes = sizeof(struct __FloatArray) + (__n - 1) * sizeof(float); |
124 // printf("__n=%d nBytes=%d\n", __n, nBytes); |
127 // printf("__n=%d nBytes=%d\n", __n, nBytes); |
125 __nObj = __STX___new(nBytes); |
128 __nObj = __STX___new(nBytes); |
|
129 |
126 if (__nObj != nil) { |
130 if (__nObj != nil) { |
127 __objPtr(__nObj)->o_class = __qClass(self); |
131 __objPtr(__nObj)->o_class = __qClass(self); |
128 __STORE(__nObj, __qClass(self)); |
132 __STORE(__nObj, __qClass(self)); |
129 bcopy(__FloatArrayInstPtr(self)->f_element + __start, |
133 // bcopy is marked as deprecated |
130 __FloatArrayInstPtr(__nObj)->f_element, |
134 // bcopy( |
131 sizeof(float) * __n); |
135 // __FloatArrayInstPtr(self)->f_element, |
|
136 // __FloatArrayInstPtr(__nObj)->f_element + __start, |
|
137 // __n * sizeof(float)); |
|
138 |
|
139 memcpy( |
|
140 __FloatArrayInstPtr(__nObj)->f_element + __start, |
|
141 __FloatArrayInstPtr(self)->f_element, |
|
142 __n * sizeof(float)); |
|
143 |
132 RETURN(__nObj); |
144 RETURN(__nObj); |
133 } |
145 } |
134 } |
146 } |
135 } |
147 } |
136 } |
148 } |