From: Oliver Woodford on 29 Jan 2010 05:09 Hi all In my mex file I have a block of data stored in a buffer allocated using mxMalloc. I then want to return that data in two separate arrays, the first half in one and the second half in the other. Is this possible without moving at least one half to a new buffer? I know that I can use mxSetData to set the array pointers to the right place. I'm just wondering if splitting an allocated block in two will confuse the memory management system. For example, will it then be able to free one half without freeing the other? Thanks, Oliver
From: Rune Allnor on 29 Jan 2010 06:25 On 29 Jan, 11:09, "Oliver Woodford" <o.j.woodford...(a)cantab.net> wrote: > Hi all > > In my mex file I have a block of data stored in a buffer allocated using mxMalloc. I then want to return that data in two separate arrays, the first half in one and the second half in the other. Is this possible without moving at least one half to a new buffer? It might be *possible* from a purely techncal POV, but it would be a very stupid thing to do. > I know that I can use mxSetData to set the array pointers to the right place. I'm just wondering if splitting an allocated block in two will confuse the memory management system. For example, will it then be able to free one half without freeing the other? It will almost certainly screw up the memory managment. The safe way is to 1) Allocate space for each of the 'half-buffers' 2) Copy the data from the original buffer to the two target buffers as desired 3) Delete the original buffer The only potential problem wth this, is that there is not enough memory to handle the arrays. If that's the case, you are better off re-working the data flow outside the MEX file; i.e. process the data in smaller batches. Rune
|
Pages: 1 Prev: importing text file with "," as decimal separator Next: seaching for PCA coding |