Feb 2, 2011 at 8:57am UTC
Hi, everybody.
1 2 3 4 5 6 7 8 9 10 11 12 13
struct activity{
int id; //Activity number};
vector<activity> activity(32);
activity *p_id; //Declare a pointer
vector<int > *p_activity; //Declare a pointer
for (int i=0; i<32;i++)
{
activity[i].id=i+1;
}
I want to make assingments in for loop by using pointers to be faster.
I declared the pointers but I couldn't use them in a correct way.
1 2 3 4
for (int i=0; i<32;i++)
{
Assign values by using pointers;
}
Thanks.
Last edited on Feb 2, 2011 at 8:58am UTC
Feb 2, 2011 at 12:01pm UTC
What do you want to do with pointers? I don't see any sensible way to use them here.
Last edited on Feb 2, 2011 at 12:01pm UTC
Feb 2, 2011 at 12:07pm UTC
I just want to use pointer in a loop while assignning values.
Because, actually my vector size is very big and it takes time. So, I want to use adresses.
Feb 2, 2011 at 1:27pm UTC
In a vector of N elements you will have to do N integer assignments. There is nothing you can gain here form using pointers.
Feb 2, 2011 at 1:35pm UTC
So, when the pointers are faster to use ?
Actually I want to access to a vector which is inside structure. So, one I got the adress I will use that adress in the future. Is it correct ?
Last edited on Feb 2, 2011 at 1:38pm UTC
Feb 2, 2011 at 2:50pm UTC
You use pointers either when you're dealing with dynamic memory or when you want to avoid copying (though for the 2'nd one you should use references).
Once again, there is nothing to gain here. Think about your algorithm. Does it involve any unnecessary copies?
Feb 3, 2011 at 7:00am UTC
ok thank you very much ;)