Closed rmcrkd closed 2 years ago
Same effect from XLL.TEST
when replacing xll_test
with
xll::OPER* WINAPI xll_test(xll::OPER o) {
#pragma XLLEXPORT
int n = (int)o.val.num;
static std::unique_ptr<xll::OPER> aPtr(new xll::OPER(n, 1));
for (int i = 0; i < n; i++) {
(*aPtr.get())(i, 0) = i + 1;
}
return aPtr.get();
}
LPOPER WINAPI xll_test(LPOPER po) { // LPOPER is OPER*. You must pass by pointer.
#pragma XLLEXPORT
static OPER a;
int n = (int)po->val.num; // ensure po->xltype == xltypeNum, or po->is_num()
a.resize(n, 1);
for (int i = 0; i < n; ++i) {
a(i, 0) = i + 1;
}
return a.get();
}
Consider the
xll_test
andXLL.TEST
functions defined below.In
xll_test
I declarestatic xll::OPER a(m, n)
in accordance with the following (from README):But a consequence of
a
being static is that calls ofXLL.TEST
after the first call does not change the memory which was allocated for it during the first call. So e.g. callingXLL.TEST(3)
afterXLL.TEST(2)
essentially has no effect.What is the recommended way of dealing with this?