Sharing memory between Max and Java

    Jul 14 2012 | 11:54 am
    Hi List,
    is there a way to have a piece of shared memory that could be accessed simultaneously by an external written in Java and another one written in C? Just like one can access from MXJ the data stored in a [buffer~] object (which was created with the C API of Max).
    Bonus question: is there a way to define a common mutex that can then be used by both Max and MXJ at the same time to synchronize the access to this shared block of memory?
    Thanks indeed, Ádám

    • Jul 19 2012 | 9:45 am
      Hi. Not sure I understand,if you can access the buffer from C and Java, what more do you need?
    • Jul 19 2012 | 11:39 am
      Since Java normally doesn't allow you to access memory by address the way C does, this becomes tricky. IMS, it is possible to link your Java code to a "native" method (for instance, something generated by a C-compiler), so that would be the back door.
      Still, leehu's suggestion of abusing a buffer~ as a memory area that you can access both from your [mxj] code and your C-based external might be much easier.
      Also, you can bind an arbitrary pointer to a symbol.
      Approach 4: use a global attribute.
      Any of these approaches work for you?
    • Jul 19 2012 | 11:49 am
      I think access through globals makes sense as it is cleaner, but they are much slower so if performance is a real issue that may be unacceptable I guess.
      as to the other part about synchronisation for access to the shared area, i don't know of anything like this in max. would be interested to know if anyone has solved this in a safe way