[erlang-questions] cnode interface memory allocation

Dror Mein drormein@REDACTED
Mon Sep 8 12:35:05 CEST 2014


I'll try to clarify the problem.
I have a char * in my code, which I want to erl_send to the erlang node. The erl_send function accepts as input an ETERM* pointer. I need to turn char* to ETERM*. The current way is by erl_mk_binary, which allocates memory.
Is there a way to pass the char * to erl_send without the unnecessary memory allocation.

I thought of pre-creating an ETERM struct, and only changing the binary pointer to the char* (before running erl_send). This way I can send multiple char* buffers without the need to create multiple ETERM pointers.


The point of all this is to reduce run-time for the erl_send process


On Monday, September 8, 2014 12:55 PM, Guilherme Andrade <g@REDACTED> wrote:
 


(Sorry, missed the subject -- you are indeed talking about a C node. Please ignore some of my previous phrasing.)


On 08/09/14 10:34, Guilherme Andrade wrote:

Hi Drod,

Assuming your application is a C node, and that the library
      codebase is the same as for NIFs and whatnot, I'd expect that
      allocating structures / copying data is the appropriate behaviour
      when creating Erlang terms -- it's the simple way to transfer that
      data back to Erlang avoiding ownership issues and mutable state
      (or at least making it much harder to unintentionally do it.)

I've only dealt with NIFs though, and am not an expert on them, so
      probably someone else can probably clarify this better.


Cheers,


On 08/09/14 10:08, Dror Mein wrote:

Hi all,
>I'm writing a c application that communicates with an erlang node. In order to send messages to the node I need to create erlang terms (ETERM structure).
>it appears that all functions in the C library "erl_eterm" allocate memory when creating erlang terms. 
>For example, erl_mk_binary copies the binary provided to it, instead of only creating the pointer.
>I want to prevent this memory allocation to optimize speed. 
>Has anyone done this before? 
>Is there a better way to create eterms?
>
>
>Thanks
>
>
>_______________________________________________
erlang-questions mailing list erlang-questions@REDACTED http://erlang.org/mailman/listinfo/erlang-questions 

-- 
Guilherme https://www.gandrade.net/ PGP: 0x35CB8191 / 1968 5252 3901 B40F ED8A  D67A 9330 79B1 35CB 8191 



_______________________________________________
erlang-questions mailing list erlang-questions@REDACTED http://erlang.org/mailman/listinfo/erlang-questions 

-- 
Guilherme https://www.gandrade.net/ PGP: 0x35CB8191 / 1968 5252 3901 B40F ED8A  D67A 9330 79B1 35CB 8191 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140908/53d15df7/attachment.htm>


More information about the erlang-questions mailing list