Ask Your Question
0

Why does a response vector of type geometry_msgs/PoseStamped[] poses in a service always has 24 elements? (c++) [closed]

asked 2016-06-20 07:08:42 -0600

pablocesar gravatar image

Hi guys,

I can't explain what is happening, maybe it is just my compiler, or my ROS version, but every time that I want to use the response vector poses (of type geometry_msgs/PoseStamped[]) it has 24 places, so if I ask for the size before assigning any value to it:

bool generate_robot_targets_service(robot_pick_place::GenerateRobotTargets::Request  &req, robot_pick_place::GenerateRobotTargets::Response &res){    
        int poses_size = sizeof(res.poses);
        std::cout << "The size of poses is:  " << poses_size << std::endl;//shows: The size of poses is: 24
        return true;
}

poses_size is equal to 24. Why? I try to delete the 24 ? (whatever they are) using the erase() vector method and it gives a core dumped error (like always). I could try creating a vector pointer and assigning it to the res.poses to point to the new memory, but still, Why does it start with 24 positions filled with garbage?

Any idea is welcome, please comment.

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by pablocesar
close date 2016-06-20 08:40:10.214856

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-06-20 07:20:09 -0600

mgruhler gravatar image

sizeof() returns the size in bytes of the object representation of the respective type. Thus, on a 64bit system (I'm assuming you have this), this is 24 bit for a vector (see e.g. this blog post, first bullet point), if it is empty.

If you want to have the number of elements, use res.poses.size() (see here).

edit flag offensive delete link more

Comments

Sorry, it is actually my mistake (a basic one, I guess I'm sleepy) for being using a vector as an array, for vectors it is indeed vector.size() for getting the size of it, thanks!

pablocesar gravatar imagepablocesar ( 2016-06-20 07:46:25 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-06-20 07:08:42 -0600

Seen: 175 times

Last updated: Jun 20 '16