I just recently helped someone with an issue of saving an array to stack data beyond the existence of that stack frame. However, the error was one level deep, something like this:

int[] globalargs;

void foo(int[] args...)
{
   globalargs = args;
}

void bar()
{
   foo(1,2,3); // passes stack data to foo.
}

One thing I suggested is, you have to dup args. But what if you call it like this?

void bar()
{
   foo([1,2,3]);
}

Then you just wasted time duping that argument. Instead of a defensive dup, what if we had a function ensureHeaped (better name suggestions?) that ensured the data was on the heap? If it wasn't, it dups the original onto the heap. It would be less expensive than a dup when the data is already on the heap, but probably only slightly more expensive than a straight dup when the data isn't on the heap.

Would such a function make sense or be useful?

-Steve

Reply via email to