any problem if there are too many arrays as parameters for a function

M

MBALOVER

Hi all,

I am writing a function. I need to pass to this function about 10 2-D
arrays (double) each of which has a size of 1000x1000.

I am wondering if passing these big arrays as parameters for the
function will make any problem for my program?

Does it make my program run slowly?


I guess when I pass these arrays to the function, in fact only the
addresses of their first elements are actually passed to the
function. Since there is no copy from the original arrays to the
parameters, it won't make my program run slowly.

But I am not sure.

Please help.

Thanks,
 
S

santosh

MBALOVER said:
Hi all,

I am writing a function. I need to pass to this function about 10
2-D arrays (double) each of which has a size of 1000x1000.

I am wondering if passing these big arrays as parameters for the
function will make any problem for my program?

Does it make my program run slowly?


I guess when I pass these arrays to the function, in fact only the
addresses of their first elements are actually passed to the
function. Since there is no copy from the original arrays to the
parameters, it won't make my program run slowly.

Yes. Arrays are only passed by reference unless you do things like
encapsulate them into structures.
But I am not sure.

Please help.

Are you sure your function is not trying to do too much? Ten arrays
does seem a lot. If it's feasible, consider splitting up the task
(whatever it is) into smaller pieces, so that the resultant functions
can have fewer parameters.

But ten pointers won't slow down your program, but since they'll take
up some stack space (40-80 bytes probably), be very careful when
recursively calling your function.
 
B

Barry Schwarz

Yes. Arrays are only passed by reference unless you do things like
encapsulate them into structures.

If arrays were passed by reference, sizeof would evaluate to the
sizeof the array. It doesn't so they aren't
 
P

Peter Nilsson

If arrays were passed by reference, sizeof would evaluate to
the sizeof the array.  It doesn't so they aren't

If chars were passed by value to unprototyped functions,
sizeof would evaluate to the sizeof char. It doesn't, so they
aren't.
 
B

Barry Schwarz

If chars were passed by value to unprototyped functions,
sizeof would evaluate to the sizeof char. It doesn't, so they
aren't.

Since the standard specifically says chars are never passed to
unprototyped functions, why would anyone think they are. As 6.5.2.2-6
clearly states, normal integer promotions are performed and it is the
promoted value that is passed.
 
P

Peter Nilsson

Barry Schwarz said:
Since the standard specifically says chars are never passed
to unprototyped functions, why would anyone think they are.

The standard specifically says arrays are never passed to
any function, so why would anyone think _they're_ passed by
reference or value?

I'm not questioning your conclusion, but I am questioning
your argument. I posted what I saw as an equivalent fallacy.

Consider a concrete case in C++...

void foo(int (&a)[])

Here an array _is_ passed by reference, but I can't apply
your premice since I can't apply sizeof to a. Whatever
conclusion I draw is a non sequitur.
 
D

Daniel Giaimo

The standard specifically says arrays are never passed to
any function, so why would anyone think _they're_ passed by
reference or value?

I'm not questioning your conclusion, but I am questioning
your argument. I posted what I saw as an equivalent fallacy.

<nitpick>
Neither of you posted a fallacy. You both posted correct reductio
ad absurdum arguments.
</nitpick>

<snip>
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top