herumi / bls

288 stars 132 forks source link

How to avoid calling mclBnXX_clear when the type is instantiated as a static variable #100

Closed gogoex closed 1 year ago

gogoex commented 1 year ago

Thank you for your help in #98 and #99.

If we can only call mclBnXX_clear function when a class containing mcl classes is instantiated as a non-static variable, and avoid calling it when the class is instantiated as a static variable, that can be our solution. In pseudo code,

struct A {
  mclBnXX x;
  A() {
    if not instantiated as a static variable {
      mclBnXX_clear(&x)
    }
  }
};

Do you have any idea how this can be achieved?

herumi commented 1 year ago

Why do you call blsInit at first? Your strategy seems very cumbersome. If you want to clear those variables before calling blsInit, then how about memset(&x, 0, sizeof(x)) instead of mclBnXX_clear?

gogoex commented 1 year ago

Thanks. I will have it a try. I have one question; is calling memset for the top-level structure equivalent to calling memset for each leaf-level type of a structure regardless of the architecture or the compiler used? Or is it safer to call memset for each leaf-level type i.e. uint64_t in this case?

gogoex commented 1 year ago

That solved our problem. Thanks. I will close this issue