Making a shared Lib for Max


    Nov 09 2006 | 11:05 pm
    Hi list,
    I am in the process of figuring out how to make a shared library for a set of Max/MSP externals I am writing. The idea is to set up a bunch of often used functions and tables (sines and cosines) to be available in the Max space to all my externals loaded. I don't want to have to build a wavetable inside each external the uses it. I want to have each custom external of mine be able to access a table or a function stored in memory in the Max environment. I think TapTools is doing something like that.
    I was wondering if someone was willing to give me some suggestions or maybe even share some code on how to accomplish such a task. I know that a while ago David Z. released some guidelines on how to do this. However they were based on Codewarrior. Now with Xcode and UB it's a different story. Hope someone can shed some light on this.
    Thanks a lot for any advice.
    - Luigi
    ------------------------------------------------------------ THIS E-MAIL MESSAGE IS FOR THE SOLE USE OF THE INTENDED RECIPIENT AND MAY CONTAIN CONFIDENTIAL AND/OR PRIVILEGED INFORMATION. ANY UNAUTHORIZED REVIEW, USE, DISCLOSURE OR DISTRIBUTION IS PROHIBITED. IF YOU ARE NOT THE INTENDED RECIPIENT, CONTACT THE SENDER BY E-MAIL AT SUPERBIGIO@YAHOO.COM AND DESTROY ALL COPIES OF THE ORIGINAL MESSAGE. WITHOUT PREJUDICE UCC1-207. ------------------------------------------------------------
    Yahoo! Music Unlimited Access over 1 million songs. http://music.yahoo.com/unlimited

    • Nov 09 2006 | 11:23 pm
      On Nov 9, 2006, at 3:05 PM, Luigi Castelli wrote:
      > I was wondering if someone was willing to give me some > suggestions or maybe even share some code on how to > accomplish such a task. I know that a while ago David > Z. released some > guidelines on how to do this. However they > were based on Codewarrior. Now with Xcode and UB it's > a different story. Hope someone can shed some light on > this.
      Please check out developer.apple.com for more info as to making a shared library or framework. If you still have specific questions after checking out apple's general documentation, we'd be happy to answer them.
      -Joshua
    • Nov 19 2006 | 9:45 pm
      Hi there,
      that's how the getvalueof method ought to be implemented according to the Pattr SDK:
      t_max_err quadpan_tilde_getvalueof(t_quadpan_tilde *x, long *ac, t_atom **av) { if (ac && av) { if (*ac && *av) { // memory has been passed in - use it } else { // no memory passed in - allocate it *av = (t_atom *)getbytes(sizeof(t_atom)); if (*av == NULL) { *ac = 0; return MAX_ERR_OUT_OF_MEM; } } *ac = 1; atom_setfloat(*av, x->val); } return MAX_ERR_NONE; }
      However, wouldn't I need to free the memory allocated with getbytes at the end of the function ?
      Thanks.
      - Luigi
      ------------------------------------------------------------ THIS E-MAIL MESSAGE IS FOR THE SOLE USE OF THE INTENDED RECIPIENT AND MAY CONTAIN CONFIDENTIAL AND/OR PRIVILEGED INFORMATION. ANY UNAUTHORIZED REVIEW, USE, DISCLOSURE OR DISTRIBUTION IS PROHIBITED. IF YOU ARE NOT THE INTENDED RECIPIENT, CONTACT THE SENDER BY E-MAIL AT SUPERBIGIO@YAHOO.COM AND DESTROY ALL COPIES OF THE ORIGINAL MESSAGE. WITHOUT PREJUDICE UCC1-207. ------------------------------------------------------------
      Sponsored Link
      Mortgage rates near 39yr lows. $310k for $999/mo. Calculate new payment! www.LowerMyBills.com/lre
    • Nov 19 2006 | 9:50 pm
      Luigi Castelli wrote:
      > Hi there, > > that's how the getvalueof method ought to be > implemented according to the Pattr SDK: > > t_max_err quadpan_tilde_getvalueof(t_quadpan_tilde *x, > long *ac, t_atom **av) > { > if (ac && av) { > if (*ac && *av) { > // memory has been passed in - use it > } else { > // no memory passed in - allocate it > *av = (t_atom *)getbytes(sizeof(t_atom)); > if (*av == NULL) { > *ac = 0; > return MAX_ERR_OUT_OF_MEM; > } > } > *ac = 1; > atom_setfloat(*av, x->val); > } > return MAX_ERR_NONE; > } > > However, wouldn't I need to free the memory allocated > with getbytes at the end of the function ?
      As far as I undertand it: No. Becasue you hand a value back to the calling function, so the calling function will hopefully take care or freeing the memory. The other case is also implemented here: the caller hands in some memory, which is probably easier to understand in terms of who frees the memory.
      Olaf
    • Nov 20 2006 | 11:10 am
      On 19-Nov-2006, at 22:45, Luigi Castelli wrote:
      > However, wouldn't I need to free the memory allocated > with getbytes at the end of the function ?
      There are many places in the Max API where a function allocates memory automatically, but it is the caller's responsibility to deallocate the memory when finished.
      I try to avoid this model wherever I can, preferring a programming model where memory is allocated and deallocated by the same module (not necessarily in the same function). I find the discipline of balancing new/free calls in my code helps me avoid memory leaks. But not everyone programs that way and it is often convenient to have memory allocated for you by a function such as xxx_getvalueof(). It just requires that the caller is well-behaved and deallocates memory when no longer needed.
      -- P.
      PS to Luigi: I'm behind on packing up the source code for you. ASAP.
      -------------- http://www.bek.no/~pcastine/Litter/ ------------- Peter Castine +--> Litter Power & Litter Bundle for Jitter Universal Binaries on the way iCE: Sequencing, Recording & Interface Building for |home | chez nous| Max/MSP Extremely cool |bei uns | i nostri| http://www.dspaudio.com/ http://www.castine.de