AllocaInst issue

Hello,

I have the following problem: I need to allocate an array. I know it's size - it's constant (ConstExpr), but my problem is that I know it only during the runtime (i.e for every variable I'm trying to allocate an array equal to size of a variable). As I understand I can't do it, since it's possible to initialize ArrayType only if I know it's size in integer units. Since I'm not able to initialize type, I can't pass it to AllocaInst. Are there any ways to solve this issue?

Of course, I can solve this issue by insertion of a cycle that will allocate an array element-by-element, but it doesn't seems as a good way.

Best,
Yaroslav.

Hello,

I have the following problem: I need to allocate an array. I know it's size - it's constant (ConstExpr), but my problem is that I know it only during the runtime (i.e for every variable I'm trying to allocate an array equal to size of a variable). As I understand I can't do it, since it's possible to initialize ArrayType only if I know it's size in integer units. Since I'm not able to initialize type, I can't pass it to AllocaInst. Are there any ways to solve this issue?

Of course, I can solve this issue by insertion of a cycle that will allocate an array element-by-element, but it doesn't seems as a good way.

The alloca instruction in LLVM has an optional second operand for the number of elements to allocate. This allows you to allocate arrays on the stack when the number of elements isn't known until run-time.

See the LLVM Language Reference Manual for more details.

-- John T.