Ask Your Question

Accessing Point<int> (Point2i) data from memory

asked 2013-07-19 03:35:31 -0600

ShadowTS gravatar image

I've a:

const Point* points

How are datas stored in memory? I need to access points[i].x and points[i].y in ARM assembly. I've tried to load 32 bit (standard int dimension) from memory starting from *points address, but my assumption that this array is stored this way seems wrong:

points[0].x, points[0].y, points[1].x, points[1].y, ...
edit retag flag offensive close merge delete


All elements are stored as a single vector in memory, using a pointer with the bitsize of the element to jump between the different subelements. For example a matrix element can be accessed by using the<char>(x,y) if the type of the mat elements are CV_8UC1. I guess this is the same for the points element.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-19 04:53:47 -0600 )edit

What you can also try is to use std::vector of points. This will eliminate the malloc (did you forget to allocate memory in any case? ) step and problems associated with pointers. For example, std::vector<Point> points; and use push_back to add points to the vector, like this, points.push_back( Point(x,y) ); and you can access by points[i] where i is index.

Try to use vectors whenever possible (but sadly there are drawbacks too. :( But on the bright side, its way better and easy to handle than pointers)

Prasanna gravatar imagePrasanna ( 2013-07-19 06:45:21 -0600 )edit

Probably I have not explained well. Extending to Array is not the problem here.

Let's suppose we have a single Point (or Point2i, it is the same). Starting from the memory address of Point I have to access to Point.x and Point.y without calling .x and .y because "Point.x" is not a valid memory address. I'll use the memory address to access Point.x and Point.y in an Assembly method. The question is more like: how is Point2i structure stored in memory?

ShadowTS gravatar imageShadowTS ( 2013-07-19 08:19:23 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2013-07-24 03:31:55 -0600

ShadowTS gravatar image

Probably I've made a mistake before asking this question.

Using the memory address of the pointer:

const Point* points

You can access Points data. There are only "x"s and "y"s stored, more precisely, starting from the address of the pointer, in this way:

points[0].x, points[0].y, points[1].x, points[1].y, ...

Where every element is 4 byte (32 bit).

edit flag offensive delete link more


So basically what you considered as wrong code, does work? :D

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-24 03:51:30 -0600 )edit

Yes, probably the first time I've implemented assembly in a wrong way. Today I've tried again to check what data are extracted from memory and I've found they are "x"s and "y"s in sequence.

ShadowTS gravatar imageShadowTS ( 2013-07-24 06:01:32 -0600 )edit

Question Tools


Asked: 2013-07-19 03:35:31 -0600

Seen: 5,778 times

Last updated: Jul 24 '13