# struct pointer

This topic is 3818 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hy. I read about dont use array or collection for store the 3d point in a model. Then how to indexes a havy structure of point: struct 3dpoint { float x; float y; float z } 3dpoint point= new 3dpoint(); point->x = 1; point->y = 0; point->z = 1; ..ecc for 1000000 next how to access at the 20000 point with pointers? or scroll all the 100000 points? thanks.

##### Share on other sites
struct 3dpoint
{
float x;
float y;
float z
}

You didn't specify the language you are using, but I guess from syntax it's C++.

I suggest using std::vector so:

#include <vector>

std::vector<3dpoint> points;

for (int i=0;i<number_of_points;i++)
{
3dpoint point;
point.x = 1;
point.y = 0;
point.z = 1;
points.push_back(point);
}

then you can refer to your points as points[number]

##### Share on other sites
Quote:
 Original post by giugioI read about dont use array or collection for store the 3d point in a model.

It seems you've been misinformed - the most natural way to have a collection of points is by storing those points in a container.

Ex (C++):

std::vector<3dpoint> vertices; // your empty collection of points

##### Share on other sites
That, and 3dpoint is an invalid identifier [wink]

##### Share on other sites
Quote:
 Original post by agi_shiThat, and 3dpoint is an invalid identifier [wink]

*sighs* - 'Course it is [rolleyes]

##### Share on other sites
if you cant use a vector,

size_t num = 1000000;
point3d points = new point3d[num];

for (size_t i=0; i<num; ++i) {
points.x = 1;
points.y = 0;
points.z = 0;
}

size_t which = 46463;
int x = points[which].x;
int y = *(points+which).y;
//int z = *(points+which*sizeof(point3d)); //wrong

delete[] point3d;

##### Share on other sites
thanks , this is ok

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633734
• Total Posts
3013590
×