Passing a variable from one function to another.


Aug 1, 2011 at 10:46pm


you can do something like that (even if IMHO you should avoid to free/alloc memory each time) ;
you don’t need to use float *storage = x->storage ;
correct me if i didn’t understand your problem.


sysmem_freeptr (x->storage);
x->storage = (float *)sysmem_newptr (totalframes * b_nchans * sizeof(float)); 

memcpy (x->storage, b_samples + (startframe * b_nchans), totalframes * b_nchans * sizeof(float));

n = totalframes;

fbuf_paste (x, n);

fbuf_paste (t_myObject *x, long n)
float *toto = x->storage;


Aug 2, 2011 at 8:46am


“You mentioned I should avoid free/alloc each time, I know this could lead to instability issues, what would you suggest?”

AFAIK : not an instability issue, but speed issue ; allocate a big one and reallocate it only in case of overflow.

“Do I need to implement a routine that waits for the buffer to update before any further action can take place ?”

Timothy Place wrote a nice paper on it, in his object74 blog ; or have a look on maxMSP t_buffer entry.
To sum up : YES, there is an ATOMIC lock to set/unset accessing the buffer.


Aug 2, 2011 at 9:06am

Hello again ;-)

“I’ve also noticed if I replace ‘memcopy’ with ‘sysmem_copyptr’ it doesn’t store any of the buffer, I’m I missing something ?

Take care, (if i’m not wrong), source and destination pointer are reversed.

More generally, when you have a question please try first to search in old threads ; as you can find severals about buffers access ;-)



You must be logged in to reply to this topic.