Coder Social home page Coder Social logo

Comments (6)

philburk avatar philburk commented on August 15, 2024

Who deletes the std::string?

from oboe.

philburk avatar philburk commented on August 15, 2024

const char * may be old school but it has advantages.
The caller does not have to delete the string.
So it can easily be used in logs.
Also std::string may cause a memory allocation, which should be avoided in real-time audio.

from oboe.

mnaganov avatar mnaganov commented on August 15, 2024

There is no need to delete the string. I think, Don is proposing to return 'std::string' by value, not as a pointer to an allocated object. And in those cases compilers usually provide optimizations to avoid unneeded allocations or copying.

The advantage of returning an std::string is that the error text may be composed on the fly.

As for the 'real-time' issue—if an error happens it's already a problem, and requires taking the error handling code path, which is allowed to be non-optimal (think of exception handling).

from oboe.

philburk avatar philburk commented on August 15, 2024

It seems like we are taking something very simple and converting it to something more complex.
If we want to add the result code to the string, we could could add a convenience function that called the simple (const char *) function then added the result code and returned a std::string.
Or the app could do that very easily.

from oboe.

dturner avatar dturner commented on August 15, 2024

The motivation isn't primarily because we want to return a result code (although it does help with that), it's that users of the Oboe library may prefer to receive a std::string over a C-style string.

Some benefits of std::string over C strings: https://embeddedartistry.com/blog/2017/7/24/stdstring-vs-c-strings

As for your point about memory allocation - this is true and we should be very clear in the comments and documentation that the convertToText method shouldn't be called in the data callback under normal conditions.

I've asked some partners for their opinions on what they'd prefer - maybe C-style strings are still en vogue for audio programmers.

from oboe.

dturner avatar dturner commented on August 15, 2024

Things are better in C++17 but Android Studio only supports up to C++14 so closing for now.

from oboe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.