What did I do wrong in this process? I know how to usualy pass Struct as a function parameter, but I'm totaly lost when it comes to array of structs and even more when i have to pass only part of an array of struct (

Code:

&(sys.aP->r)

)

thank you very much (going to bed now o.O, I will answer anything tomorrow..)

Considering he is using a, r and m as arrays, I don' think your suggestion is going to help him lots.

Well this is the case of the op proposes and the compiler disposes.
Where in the code are the variables a, r, and m defined as arrays?
They're just simple objects of type Dimension (a / r) and double (m).

Originally Posted by msh

Personally, I think that he should just rewrite accelerationsCalcul() as below and work from there.

each parameter is a pointer to an array of N elements of type Dimension(double), so change the function header to

Code:

void accelerationsCalcul(Dimension *r, Dimension *a, double *m)

The reason i used arrays for r, a and m, is that those function arguments are kinda arrays themself. Because aP is an array, that mean the function should receive 3 x N structs adresses. So i was trying to capture all those array with pointers of this kind

Code:

Dimension (*r)[N]

I think i will take msh suggestion and rewrite the function with a complete allPoint struct, but let me tell you first why i tried to avoid it in the first place. The time to run the whole program scale has N^2, and I'm looking to make N as big as my computer can handle (I hope to one day reach N =100 000, but right now I can't even reach N=10 000 without stack overflow, wich I find weird since it looks like a pretty small number to me...). The function "accelerationsCalcul" will be called a couple thousands of time so I wanted to make it as quick as possible and supply it will only what it needed. So my question is: Is passing an allPoint array to the function really slower than passing just specific part of the array?

I might add that the majority of computer calculus time will be spent inside the function "accelerationsCalcul" (wich I hope to make it run on my 3d Card with CUDA as the ultimate goal of this project after I understand how to make it run great on hte cpu first)

As itCbitC stated in post #3, r is actually a pointer to an array of N Dimension objects.

Originally Posted by Bjarne Stroustrup (2000-10-14)

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

Is passing an allPoint array to the function really slower than passing just specific part of the array?

With what I suggested, you wouldn't be passing an array to the function; you would be passing the address of your sys structure that contains the array of Point structures. This is called "passing by reference". The function doesn't get a copy of an object, just it's address, and then modifies the structure it finds at this address.

msh: My bad, I badly worded my sentence. And now that you say it, it makes perfect sense that passing an adress as function parameter is as fast regardless of if I use it to point to a big struct or a smaller one.

Without entering into too much details, is dynamic memory allocation useful when the size of "N" is known before launching the program and I know it won't change?
Or dynamic allocation will kinda of make a better use of my available memory?
And when we talk about dynamic allocation, are we talking about malloc, calloc and realloc? or some kind of linked list? (maybe this question doesn't even make sense.. I just don't know a lot about dynamic memory allocation apart that it exist, I will go read about it if that is needed for the program)

No, if you know the size of your data set will never change during run time, dynamic memory allocation and linked lists are not necessary. As a matter of fact, they would make your coding job much harder. You did well enough to define N as your array size and code everything in terms of that.

Without entering into too much details, is dynamic memory allocation useful when the size of "N" is known before launching the program and I know it won't change?

Yes, because there tends to be a much lower limit to space on the stack than the heap. That said, you could make the fixed size array global to avoid the limits of the stack... but global variables should normally be avoided.

Originally Posted by Bjarne Stroustrup (2000-10-14)

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.