MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Passing arrays to MathLink without extra memory allocation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98805] Re: Passing arrays to MathLink without extra memory allocation
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Mon, 20 Apr 2009 01:28:38 -0400 (EDT)
  • References: <gs9ek8$mso$1@smc.vnet.net> <gsbvus$5ka$1@smc.vnet.net> <gseort$ef8$1@smc.vnet.net>

Hi,

axnavaei at googlemail.com wrote:
> Hi,
> 
> Are there any other solutions for passing pointers to big data from
> mathematica to external programs? 

No

In this context, an 'external
> program' does not need to be a separate process, it could simply be a
> loadable shared library. The way another system deals with its c-extensions is
> a good example of what I mean by this.

A MahtLink program can run on a second computer, that will not work
with dynamic librarys

> 
> It seems like those official mathematica functions implemented in
> native code do not have the above constraint and it is possible to
> pass pointers without deep copying, is this correct? 

What is a official Mathematica function ?

Why do you assume that the kernel store your data in the same way as 
your code does ? Since Mathematica can store symbols, expressions, 
integers, multi-precision numbers in its lists your program would never 
know what is in the memory location. MathLink is the only way to
unfold the internal structures and to send it to an external program.


If so, how is it
> possible to implement a function like this?
> 

*IT IS NOT POSSIBLE*

And with a little cleverness in cen C-code it is not necessary.
I have C-programs that deal with several GByte of data for visualization 
and image processing tasks and I have no idea for what this should be 
good for.

Regards
   Jens

> On 18 Apr, 08:37, Jens-Peer Kuska <ku... at informatik.uni-leipzig.de>
> wrote:
>> Hi,
>>
>> a) MathLink is always buffered and
>> b) it must copy the data into a memory area
>>     that bot programs can access
>> c) your C-program can never access the memory space
>>    of an other program/process. The operating system is
>>    responsible to hinder/prevent such operations
>>
>> Regards
>>    Jens
>>
>> axnav... at googlemail.com wrote:
>>> Hi,
>>> When passing a list/array from mathematica to c using mathlink, eg
>>> when calling MLReleaseInteger32List(), it seems mathlink allocates
>>> some memory which later has to be freed, eg using
>>> MLReleaseInteger32List(). The question is, how is it possible to pass
>>> a list from mathematica to c without this c memory allocation?
>>> This example helps to make the question more clear: Assume MyFunction
>>> [BigList] to be a function implemented in c using mathlink, where
>>> BigList is a list of integers. Since BigList has been already created
>>> in mathematica and its corresponding memory has been allocated, we do
>>> not wish to allocate memory once again in c. It looks like one option
>>> is to pass BigList by reference, that is:
>>> SetProperties[MyFunction, HoldAll]
>>> In this case, does mathlink still allocate memory and copy BigList in
>>> the c side?
> 
> 


  • Prev by Date: Re: Looking for more Mathematica online user groups/forums
  • Next by Date: Re: Determining a formula with Mathematica 6
  • Previous by thread: Re: Passing arrays to MathLink without extra memory allocation
  • Next by thread: Re: Re: Passing arrays to MathLink without extra memory allocation