Items with no label
3338 Discussions

why realsense should code like this? auto&& frame : pipe.wait_for_frames()

FritzY
Beginner
1,896 Views

i saw the code example of IntelRealSense/librealsense/examples/save-to-disk/rs-save-to-disk.cpp from github.

link is https://github.com/IntelRealSense/librealsense/blob/master/examples/save-to-disk/rs-save-to-disk.cpp#L34

 line 34  for (auto&& frame : pipe.wait_for_frames())

​why code like this rather "auto frame = pipe.wait_for_frames()"

 

and line 37 if (auto vf = frame.as<rs2::video_frame>())

rather "auto vf = frame.get_depth_frame()"

 

is any better to code this way?

0 Kudos
5 Replies
FritzY
Beginner
1,666 Views

is it in order to minimize the memory cost?

0 Kudos
MartyG
Honored Contributor III
1,666 Views

The link below explains why wait_for_frames is used and the alternatives to it.

https://github.com/IntelRealSense/librealsense/issues/2422#issuecomment-423254709

Using 'video' frame is an appropriate choice when only saving data as a simple PNG, and not a file format with embedded depth matrix information such as .raw. or .bin

0 Kudos
FritzY
Beginner
1,666 Views

Thanks for reply, it 's really helpful.

But what really disturb me is why it use A reference " auto &&" to define frame, is it a better(tidy) wrriting than using " = " to define an argument(the way we usually do)?and why?

then using "as" methond to change the class of frame. on the contrary, I may use "get_depth_frame" function straightly if my purpose is to get a depth image.

Perhaps it belongs to a c++ question boundary, but i would appriciate it if you give me some suggestions.

 

0 Kudos
MartyG
Honored Contributor III
1,666 Views

My understanding is that "auto &&" makes it a 'universal reference' that can be bound to anything.

 

When programming Librealsense, my advice is to use example programs as a base reference and then adjust the code to your own style if you believe that your own method of structuring code is more suitable. Librealsense is open-source exactly so users can mold it to their needs and preferences.

0 Kudos
FritzY
Beginner
1,666 Views

My opinion is maybe it's a memory saving way to code like this. Anyway, thanks you very much.

0 Kudos
Reply