[erlang-questions] pushing a dict in the constant pool

Björn-Egil Dahlberg egil@REDACTED
Mon Jan 24 19:08:40 CET 2011


Hi,

Generate a module on the fly, compile and load it.

Something like,

new(Module, Terms) ->
   Forms = [{attribute,1,module,Module},
          {attribute,2,export,[{data,0}]},
          {function,3,data,0,[{clause,4,[],[], 	
	[erl_parse:abstract(Terms)]}]}],

     {ok, Module, Code} = compile:forms(Forms, []),
     {module,Module} = code:load_binary(Module, Module, Code),
     Module.

Use,

new(my_module, SomeDict).

my_module:data() -> SomeDict.

// Björn-Egil

On 2011-01-24 18:43, Paolo Negri wrote:
> Dear list,
>
> I would like to know if there's a way to get a dict to be stored in
> the constant pool
>
> For a list I would do
>
> get_useful_list() ->
>    [my, useful, ubiquitous, list]
> .
>
> But if I would like to have a similar function to get a dict (with up
> to few hundreds entries), how would it look like?
> My reason to look into this is in order to be able to efficiently
> distribute constant and immutable configuration data to thousands of
> processes and provide constant time lookup.
>
> Thanks for your help.
>
> Paolo
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>



More information about the erlang-questions mailing list