<div id="__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: #000000">
                                        
                                        
                                            
                                        
                                        
                                        Hi Nicolas.<div><br></div><div>I like the idea of having #allocate: ... but maybe not in ExternalType:</div><div><br></div><div>- The term "allocate:" is somewhat reserved for heap memory from the SqueakFFI perspective; See ExternalAddress class >> #allocate:.</div><div>- The counterpart #free is missing ... which means that, maybe, both #allocate: and #free should be implemented in ExternalData, not ExternalType<br><br></div><div>What about such a this programming interface:</div><div><br></div><div>data := ExternalData</div><div>   fromHandle: nil</div><div>   type: MyStruct externalType asPointerType.</div><div>data allocate.</div><div>myStruct := data asExternalStructure.</div><div><br></div><div>You could also copy it back to object memory:</div><div><br></div><div>myStruct := data getExternalStructure. "get/pull/fetch ...."</div><div>data free.</div><div><br></div><div>You are proposing a way to start off in object memory. Maybe like this:</div><div><br></div><div><div>data := ExternalData</div><div>   fromHandle: nil "maybe optional?"</div><div>   type: MyStruct externalType asPointerType.</div><div>data allocateLocal.</div><div>myStruct := data asExternalStructure.</div><div><br style="font-size: 13.3333px"></div></div><div>Then we don't need to call #free. See how #allocate and #allocateLocal in ExternalData could mirror #new and #externalNew of ExternalStructure?</div><div><br></div><div>There is really an interesting releationship between ExternalStructure (incl. ExternalUnion/ExternalTypeAlias/ExternalPackedStructure) and ExternalData. Can you see it? ^__^</div><div><br></div><div>Arrays could be similar:</div><div><br></div><div>data := ExternalData type: Externaltype int32_t asPointerType.</div><div>data size: 20.</div><div>data allocate. "or #allocateLocal"</div><div><br></div><div>Now you would have an array of 20 integers. :-) Note that #allocate: with argument could inline that #size: call.</div><div><br></div><div>Best,</div><div>Marcel</div><div class="mb_sig"></div>
                                        
                                        <blockquote class="history_container" type="cite" style="border-left-style: solid;border-width: 1px;margin-top: 20px;margin-left: 0px;padding-left: 10px;min-width: 500px">
                        <p style="color: #AAAAAA; margin-top: 10px;">Am 21.06.2020 13:20:44 schrieb commits@source.squeak.org <commits@source.squeak.org>:</p><div style="font-family:Arial,Helvetica,sans-serif">Nicolas Cellier uploaded a new version of FFI-Kernel to project FFI:<br>http://source.squeak.org/FFI/FFI-Kernel-nice.118.mcz<br><br>==================== Summary ====================<br><br>Name: FFI-Kernel-nice.118<br>Author: nice<br>Time: 21 June 2020, 1:20:34.369348 pm<br>UUID: a8c48997-991d-4e32-9b67-6d93fc0dabe0<br>Ancestors: FFI-Kernel-mt.117<br><br>Add the ability to allocate: an ExternalType or an ExternalStructure/Alias.<br><br>It's equivalent to new: but we want a specific idiom, C types are not exactly classes.<br><br>Add the ability to compare aliases (at least for equality)<br><br>=============== Diff against FFI-Kernel-mt.117 ===============<br><br>Item was added:<br>+ ----- Method: ExternalStructure class>>allocate: (in category 'instance creation') -----<br>+ allocate: anInteger<br>+       "Create an ExternalData with enough room for storing an array of size anInteger of such structure"<br>+         ^self externalType allocate: anInteger!<br><br>Item was added:<br>+ ----- Method: ExternalType>>allocate: (in category 'external data') -----<br>+ allocate: anInteger<br>+         "Allocate space for containing an array of size anInteger of this dataType"<br>+        <br>+     | handle |<br>+   handle := ByteArray new: self byteSize * anInteger.<br>+  ^(ExternalData fromHandle: handle type: self) size: anInteger!<br><br>Item was added:<br>+ ----- Method: ExternalTypeAlias>>= (in category 'comparing') -----<br>+ = anExternalTypeAlias<br>+       ^self class = anExternalTypeAlias class and: [self value = anExternalTypeAlias value]!<br><br>Item was added:<br>+ ----- Method: ExternalTypeAlias>>hash (in category 'comparing') -----<br>+ hash<br>+     ^self class hash hashMultiply bitXor: self value hash!<br><br><br></div></blockquote></div>