Sharing memory between Max and Java

Jul 14, 2012 at 11:54am

Sharing memory between Max and Java

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

#35912
Jul 19, 2012 at 9:45am

Hi. Not sure I understand,if you can access the buffer from C and Java, what more do you need?

#123033
Jul 19, 2012 at 11:39am

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?

#123034
Jul 19, 2012 at 11:49am

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

#123035

You must be logged in to reply to this topic.