Vector storage in C++

前端 未结 5 531
轮回少年
轮回少年 2021-02-05 01:08

I wish to store a large vector of d-dimensional points (d fixed and small: <10).

If I define a Point as vector, I think a v

5条回答
  •  [愿得一人]
    2021-02-05 01:17

    The only way to be 100% sure how your data is structured is to fully implement own memory handling..

    However, there are many libraries that implement matrices and matrix operations that you can check out. Some have documented information about contiguous memory, reshape etc. (e.g. OpenCV Mat).

    Note that in general you can not trust that an array of Points will be contiguous. This is due to alignment, allocation block header etc. For example consider

    struct Point {
       char x,y,z;
    };
    
    Point array_of_points[3];
    

    Now if you try to 'reshape', that is, iterate between Point elements relaying on the fact that points are adjacent in the container - than it is most likely to fail:

    (char *)(&array_of_points[0].z) != (char *)(&array_of_points[1].x)
    

提交回复
热议问题