3

I'm have an object with around 25 fields in it.

int idOfObjectTracker;
mapping (uint => object)listofobjects;

struct object {
string _1;
string _2;
   ...
string _25;
}

i'm trying to " modifiy all the propreties at once.

function newObject(string _1,string _2,...){
   object o = listofobjects[idOfObjectTracker++]
   o._1 = _1;
     ....
   o._25 = _25;
}

Obviously this doesn't work and i can't seem to find a workaround since i don't want my client to provide the id so splitting creation in multiple function wouldn't work either since the id would be messed up.

How do you normally proceed in this situation ?

3

Greater than 15 local variables and you'll hit a StackTooDeepException, as you've seen.

If your struct contains only strings, and you're trying to update them all at the same time, then other than splitting across several instantiation functions I don't think there's much you can do. (Which you've said isn't possible in your case.)

For cases where there's a more complex set of local variables, there are various techniques that could be employed to reduce their use of the stack.

Solidity and the EVM have their limitations. Remember that you're executing your code on a distributed platform, not in the resource-rich environment you might be used to with other languages and platforms.

1
  • my struct doesn't contain only strings it could be a mix of all types , i may have choosed the wrong example, just wanted to take something over the 16-17 limit. I'm trying to find a way that could make the in chain id generation work over multiple transactions with all the transactions not being aware of each others ids beforehand.Array as inputs aren't implemented yet so i can't seem to find a way to do it.. – solinooby Jun 25 '16 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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