0

I'm newbie in c++ and try to implement a native library for my android app to encode and decode audio using NDK and FFmpeg, during the implementation process I noticed that I quite often use pointers to std::pair<uint_8t *, int> to storing audio samples data and data length in it.

Also i can create a struct with the same types of variables that my pair has and use this struct instead of the pairs, but since I don't have much knowledge in c++ I'd like to know which type is more suitable in my work, which is more fast and has low memory usage and also might there are more effective types in c++ that i don't know?

As for my native library it just encodes/decodes and resamples audio and it doesn't have async functions, threads and so on and executes in the same thread that called it's methods from java/kotlin layer.

easy_breezy
  • 1,073
  • 7
  • 18
  • Also: https://stackoverflow.com/q/2236182/4389800 – P.P Apr 11 '20 at 13:29
  • 1
    `std::pair` is a `struct` containing two members. The only practical difference of defining your own `struct` type to hold two associated values is that the members can have any name your like, rather than `first` and `second`. Also, why are you using pointers to `std::pair` instead of standard containers or (if you are creating a single instance of pair) simply using variables of automatic storage duration? It seems you are coding in C++ like you would in Java, despite them being very different languages, and constructs that look the same behaving differently. – Peter Apr 11 '20 at 13:32
  • @Peter I use pointers to std::pair because I didn't find more effective way to return null from a method in case of the result doesn't have data or should I just return an empty pair with null data and zero length of data? – easy_breezy Apr 11 '20 at 13:48
  • C++11 and later, look up `std::optional` – Peter Apr 12 '20 at 01:35

0 Answers0