469,315 Members | 1,565 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

passing large arrays to functions

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
2 1752
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

<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.

Similar topics

1 post views Thread by Kurt Richardson | last post: by
11 posts views Thread by John Pass | last post: by
17 posts views Thread by mr.resistor | last post: by
17 posts views Thread by =?Utf-8?B?U2hhcm9u?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.