From: Andrew S. <str...@as...> - 2006-11-08 16:51:52
|
David Cournapeau wrote: > Andrew Straw wrote: > >> David Cournapeau wrote: >> >> >>> - To send data from the calling process to matlab, you first have to >>> create a mxArray, which is the basic matlab handler of a matlab array, >>> and populating it. Using mxArray is very ackward : you cannot create >>> mxArray from existing data, you have to copy data to them, etc... >>> >>> >> My understanding, never having done it, but from reading the docs, is >> that you can create a "hybrid array" where you manage the memory. Thus, >> you can create an mxArray from existing data. However, the docs >> basically say that this is too hard for most mortals (and they may well >> be right -- too painful for me, anyway)! >> >> > Ok, I have looked at it. It is not hard, it is just totally brain > damaged: there is no way to destroy a mxArray without destroying the > data it is holding, even after a call with mxSetPr. So the data > referenced by the pointer given to mxSetPr is always destroyed by > mxDestroyArray; I don't see any way to use this to avoid copy... They > could at least have given a function which frees the data buffer and one > which destroys the other stuff; as it is, it is totally useless, unless > you don't mind memory leaks. > It does sound brain damaged, I agree. But here's a suggestion: can you keep a pool of unused mxArrays rather than calling mxDestroyArray? I guess without the payload, they're just a few bytes and shouldn't take up that much space. |