224 |
224 |
225 To release all memory call #releaseAllMemory which simply sets the |
225 To release all memory call #releaseAllMemory which simply sets the |
226 AllocatedInstances class variable to nil (thus releasing those refs). |
226 AllocatedInstances class variable to nil (thus releasing those refs). |
227 |
227 |
228 Example (automatic freeing as soon as ref to buffer is gone): |
228 Example (automatic freeing as soon as ref to buffer is gone): |
229 |buffer| |
229 |buffer| |
230 |
230 |
231 buffer := ExternalBytes unprotectedNew:100. |
231 buffer := ExternalBytes unprotectedNew:100. |
232 ... |
232 ... |
233 |
233 |
234 |
234 |
235 Example (manual freeing - never freed, if ref to buffer is gone): |
235 Example (manual freeing - never freed, if ref to buffer is gone): |
236 |buffer| |
236 |buffer| |
237 |
237 |
238 buffer := ExternalBytes new:100. |
238 buffer := ExternalBytes new:100. |
239 ... |
239 ... |
240 buffer free |
240 buffer free |
241 |
241 |
242 |
242 |
243 Example (delayed automatic freeing as soon as ref to buffer is gone): |
243 Example (delayed automatic freeing as soon as ref to buffer is gone): |
244 |buffer| |
244 |buffer| |
245 |
245 |
246 buffer := ExternalBytes new:100. |
246 buffer := ExternalBytes new:100. |
247 ... |
247 ... |
248 buffer unregister |
248 buffer unregister |
249 |
249 |
250 This class only supports unstructured external data |
250 This class only supports unstructured external data |
251 - see the companion class ExternalStructure for more. |
251 - see the companion class ExternalStructure for more. |
252 |
252 |
253 Notice: support for external data is still being developed - |
253 Notice: support for external data is still being developed - |
254 a parser for C structure syntax and typedefs is on the way, |
254 a parser for C structure syntax and typedefs is on the way, |
255 making shared data with C programs much easier in the future. |
255 making shared data with C programs much easier in the future. |
256 |
256 |
257 Also notice, that this class may not be available or behave different |
257 Also notice, that this class may not be available or behave different |
258 in other smalltalk systems, making code using it very unportable. |
258 in other smalltalk systems, making code using it very unportable. |
259 It is provided for C interfacing only. |
259 It is provided for C interfacing only. |
260 |
260 |
266 reclaimed by the oldspace colletor. |
266 reclaimed by the oldspace colletor. |
267 Anyway, for portability, we strongly warn from using this as a substitute |
267 Anyway, for portability, we strongly warn from using this as a substitute |
268 for byteArrays; it is meant for shared data with external C-functions ONLY. |
268 for byteArrays; it is meant for shared data with external C-functions ONLY. |
269 |
269 |
270 Debugging: |
270 Debugging: |
271 since all manual memory systems are subject of obscure errors, |
271 since all manual memory systems are subject of obscure errors, |
272 you may want to turn malloc-tracing on; this traces all allocations/frees |
272 you may want to turn malloc-tracing on; this traces all allocations/frees |
273 done here. To do this, evaluate: 'ExternalBytes mallocTrace:true'. |
273 done here. To do this, evaluate: 'ExternalBytes mallocTrace:true'. |
274 |
274 |
275 In addition, you may turn on full debugging (with 'ExternalBytes mallocDebug:true'); |
275 In addition, you may turn on full debugging (with 'ExternalBytes mallocDebug:true'); |
276 if turned on, all malloc/realloc requests are remembered and later free / realloc |
276 if turned on, all malloc/realloc requests are remembered and later free / realloc |
277 requests validated against this list (i.e. to detect freeing unallocated chunks). |
277 requests validated against this list (i.e. to detect freeing unallocated chunks). |
278 |
278 |
279 To benefit from this in C-code, we recommend you use __stx_malloc() / __stx_free() |
279 To benefit from this in C-code, we recommend you use __stx_malloc() / __stx_free() |
280 instead of malloc() / free(). To do so, redefine them in a header file (or cc comand line) |
280 instead of malloc() / free(). To do so, redefine them in a header file (or cc comand line) |
281 and recompile your external c-libraries with this. |
281 and recompile your external c-libraries with this. |
282 |
282 |
283 I used this here to find memory leaks in the Xt libraries (there are still some in |
283 I used this here to find memory leaks in the Xt libraries (there are still some in |
284 the HTML widget ...). If mallocDebug is on, #dumpMallocChunks will print out what is |
284 the HTML widget ...). If mallocDebug is on, #dumpMallocChunks will print out what is |
285 leftOver. This may help to find trouble spots in your C-code. |
285 leftOver. This may help to find trouble spots in your C-code. |
|
286 |
|
287 [author:] |
|
288 Claus Gittinger |
286 " |
289 " |
287 ! |
290 ! |
288 |
291 |
289 examples |
292 examples |
290 " |
293 " |