Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Consider the following code:
As it is now, all the matching
actualCall().withOutputParameter()s will read the same memory that will contain garbage, that is, where the local variablesiandjused to be before the function returned.Is there a painless way to make it work properly? If so, I'm unaware of it.
One could
new()the temporary storage before everyexpectOneCall()and thendelete()it afteractualCall(), yes. But this is painful to look at, especially when you don't do that forwithIntParameter()and similar. And if I'm not mistaken it can lead to memory leaks if theactualCall()never happens. At least that's how I see the cleanest possible version of it:As compared to when the parameters aren't output:
As another note, it is highly unobvious that you have to keep the buffers alive yourself. And I don't think docs say that anywhere, too. I personally spent quite some time debugging my first set of tests using output parameters exactly due to that, and also found a couple places in our code base where others made the same mistake but it didn't blow up.
P.S. Does
withMemoryBufferParameter()copy its data? What aboutwithParameterOfType()?