title: Size of types in LLVM
body: <p>We are currently building a compiler in Java that uses LLVM as intermediate code representation. We use several types and we need to allocate memory for them, using malloc for instance.</p>
  
  <p>I would like to know how to compute the size that elements will need in memory: pointers, structures, ...</p>
  
  <p>I know that we can use DataLayout if we use the LLVM API, but unfortunately we don't use it and we generate LLVM code "by hand" (mainly because we were not able to find a decent and easy to use Java binding). </p>
  
  <p>So we are trying to determine how to compute the size of (complex) types, depending on the architecture the compiler will be executed on.</p>
  
  <p>Right now, we just check if we are on a 64-bit architecture or not, to determine the size of the pointers (4 or 8 bytes). We guess the size of structures by simply adding the sizes of their elements, but it seems that it is not correct (alignment should be taken into account, I guess).</p>
  
  <p>Could you help me to find a way to solve this problem?</p>
  
  <p>Thank you! </p>