CGPoint* points; CGPoint a = CGPointMake(50,50); int i; for (i=0; i<100; i++,points++) { a = CGPointMake(i,i); points = &a; } NSData *data = [NSData dataWithBytes:&points length:sizeof(*points)];
Incorrect code.
(1) You need an array of points. Just a CGPoint* points; declaration CGPoint* points; won't create an array of points, just an uninitialized CGPoint pointer. You must allocate space for the array using
CGPoint points[100];
or
CGPoint* points = malloc(sizeof(CGPoint)*100);
Remember the free points if you chose the malloc method.
(2) To copy a value to the contents of a pointer, you need to use
*points = a;
But I suggest you keep the points pointer invariant in a loop, since you are going to reuse it later. Use the syntax of the points[i] array.
(3)
sizeof(*points)
Since *points is just one CGPoint, therefore sizeof is always 8 bytes. You need to multiply the result by 100 to get the correct length.
(4)
[NSData dataWithBytes:&points ...
points already a pointer to the actual data. You no longer need to take the address. Just pass points directly.
So the final code should look like
CGPoint* points = malloc(sizeof(CGPoint)*100);
source share