In the simple blog dapp (https://github.com/EOSIO/eosio-project-demux-example) the table (for posts) was defined in the contract but is not instantiated as a field.

What are the advantages/disadvantages using a contract field over creating the table in each action. Is one more efficient RAM/CPU/bandwith-wise for the user or the contract account?

Code for creating in each action: void action(...) { post_table poststable(_self, _self); posttable.find(...); } ...

Code for field of contract:

explicit blog(account_name self) : contract(self) poststable(_self, _self) {} post_table poststable; void action(...) { posttable.find(...); ...

  • Also curious if it even makes a difference. I guess if your action calls subfunctions, which always create a new table, a member/field or giving the index by parameter is better.
    – tmm
    Sep 20, 2018 at 13:44
  • I think creating table in every action is not good in case of ram and cpu usage.But if we create a new action for that table and inline call that action inside another action that will also use ram as well . So we should know which one consume less resource creating a table in very action or making a new action, and that depend on our usecase as I think. May be there are more profound solutions . Sep 21, 2018 at 7:23

2 Answers 2


Both options are valid and it depends on the case. The first argument of multi_index object is the "owner" (code) of the table and the second is the "context" (scope). In practice you have a different set of table rows for each scope.

Answering your question, if you create the multi_index object inside an action, you may use the parameters to determine the table scope and therefore its content. That initialization make the action to consume more CPU than if the multi_index object were initialized in the constructor once.

On the other hand,creating a multi_index object in the constructor is optimal from CPU perspective but you can't change the scope of that table.

In your example, creating a multi_index object with parameters (_self, _self) is better to do it in the constructor.


Actually this code is to execute table actions which is definitely defined in hpp file as structure.In execution of emplace action on table it uses ram memory and after execution of modify action on table it uses cpu cycles and net bandwidth.

  • So, you think it does not make any difference?
    – friedger
    Sep 22, 2018 at 4:52
  • These commands are not used to create table i think you misunderstood my comment
    – Mr.Y
    Sep 22, 2018 at 4:59
  • I meant "create the table object" that executes the table actions. I don't talk about creating a multi index table struct.
    – friedger
    Sep 22, 2018 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.