passing large arrays to functions

D

dave.harper

I'm relatively new to C++, but have a question regarding functions and
arrays. I'm passing a relatively large array to a function several
thousand times during the course of a loop, and it seems to get bogged
down. Do the arrays previously passed to the function stay memory
resident? If not, what's causing it and what can I do to correct it?

Thanks,
Dave
 
V

Victor Bazarov

I'm relatively new to C++, but have a question regarding functions and
arrays. I'm passing a relatively large array to a function several
thousand times during the course of a loop, and it seems to get bogged
down.

"Seems"? What are the indicators? Have you timed it? If so, what tools
did you use to time? If not, go time it.
Do the arrays previously passed to the function stay memory
resident? If not, what's causing it and what can I do to correct it?

How should we know? Post your code, then we can talk.

V
 
H

Howard

I'm relatively new to C++, but have a question regarding functions and
arrays. I'm passing a relatively large array to a function several
thousand times during the course of a loop, and it seems to get bogged
down. Do the arrays previously passed to the function stay memory
resident? If not, what's causing it and what can I do to correct it?

Thanks,
Dave

Unless you're passing an array as a member of another object (and that
object is being passed by value), then you're not actually passing the array
at all, but rather the address of its first member. So there should be no
slowdown caused by that. And no, nothing you previously passed to any
function is cached in any way. But that doesn't matter, since as I said,
you're really only passing an address, not the whole array.

As for what's causing the slowdown, without seeing any code, it would be
hard to speculate. Perhaps it's just your loop design. Perhaps you've got
a loop inside that function as well as the loop that calls it, which is
giving you Order(n-squared) performance? No way for us to tell without
seeing the code, though.

-Howard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top