Size of Ciphertexts and Plaintexts in Memory

Hi,

I started working with OpenFHE recently and was wondering if there is an easy way to get sizes of certain objects in memory. I am mainly interested in Ciphertexts and Plaintexts.

There is no direct OpenFHE function to give the memory occupied by each ciphertext or plaintext object. The sizes can be accurately estimated since the ciphertexts and encoded plaintexts are composed of polynomials (vectors of size matching the ring dimension \times the number of RNS moduli [roughly the multiplicative depth] ) For ciphertexts and keys, you can also serialize them and look at the size of files.

Thanks for the fast response. Based on that I have written the following function:

using OFHECtxt = lbcrypto::Ciphertext<lbcrypto::DCRTPoly>;

size_t ctxt_size(OFHECtxt& ctxt) {
  size_t size = 0;
  for (auto& element : ctxt->GetElements()) {
    for (auto& subelements : element.GetAllElements()) {
      auto lenght = subelements.GetLength();
      size += lenght * sizeof(subelements[0]);
    }
  }
  return size;
};