By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,694 Members | 1,294 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,694 IT Pros & Developers. It's quick & easy.

passing large arrays to functions

P: n/a
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

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
da*********@gmail.com wrote:
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
Jul 23 '05 #2

P: n/a

<da*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.