[erlang-questions] Luerl and dynamically created lists
Tue May 21 20:05:47 CEST 2013
Variables in Erlang are no problem. In fact in one sense they don't even exist. An Erlang variable is not like a variable in imperative or OO languages, a "hole" where you can store data, but more just a reference to data which the compiler uses.
Atoms, however, definitely do exist. :-) They are literal constants with a name. And you should definitely avoid dynamically creating atoms in an uncontrolled fashion or you will eventually fill the atom table and crash the system.
With Luerl this is no problem as it never creates or uses atoms. Well, to be honest it uses 3: true, false and nil. All Luerl state is kept in a big data structure (a deep nested structure of tuples, lists, records, dicts and arrays) which is passed in when you "call" Luerl, modified as execution proceeds and finally returned to be used in the next call to Luerl. As this is a normal Erlang data structure so the Erlang GC will cleanup and reclaim unused data. You should, however, call the Luerl GC occasionally, either from Erlang by doing:
NewState = luerl:gc(State),
and then continue with NewState, or from inside Lua with "collectgarbage('collect')".
Each Luerl invocation has its own separate state with no sharing. Note that this state contains everything, all tables, stack data, local variables everything. Whether this is a good or bad thing can be discussed. This means that if you want to send Lua data, for example a table, from one process to another you must first decode into an Erlang representation, send it, then encode into Lua data in the new state. After the data has been sent there is no need to worry about erasing or reclaiming the data in the sending process, the Erlang GC will take care of it. As Luerl state is just normal Erlang data there is no need to erase or reclaim its data as it too will be reclaimed by the Erlang GC when there are no references to it.
It is actually impossible to explicitly erase or reclaim data in Erlang. This is common to most languages which have automatic memory management, like Java or Ruby, or Lua for that matter.
----- Original Message -----
> From: "Martin Hedberg" <skribent_har@REDACTED>
> To: erlang-questions@REDACTED
> Sent: Tuesday, 21 May, 2013 4:35:17 AM
> Subject: [erlang-questions] Luerl and dynamically created lists
> Hi again
> I know that it is a big "no no" to create variables dynamically in
> Erlang. However I am planning to use Mr Virdings "Luerl"
> modules so Lua-engienes (on top of Erlang processes) can handle some
> of the more simple programming tasks. While the
> Erlang processes handle the communication between them.
> When the Lua-processes produce variables dynamically I thought it
> could just pass it via the Erlang layer . However as I have
> understood it Erlang is just sending copies. Which makes me a bit
> worried about the memory.
> Is there some way to erase The Lua-content from an Erlang process
> after it have been sent?
> Best regards
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions