Giter VIP home page Giter VIP logo

Comments (2)

eao197 avatar eao197 commented on June 2, 2024

I don't think it's a good idea to place another std::string into so_5::agent_t, because in the most cases it will be an empty value.

Maybe something like that:

namespace so_5
{

// Public stuff.

struct anonymous_agent_id_t { std::array<char, N> m_ptr_as_id; };
struct named_agent_id_t { std::string_view m_name; }
using agent_name_t = std::variant<anonymous_agent_id_t, named_agent_id_t>;

[[nodiscard]]
std::string_view to_string_view(const agent_name_t & name);

class agent_t {
public:
  [[nodiscard]]
  agent_name_t
  so_agent_name() const noexcept;

private:
  std::unique_ptr<char[]> m_agent_name;
};

} /* namespace so_5 */

If the name is not specified in the constructor (via modificators for context_t object) then agent_t::m_agent_name will be nullptr. And agent_t::so_agent_name() will return an instance of anonymous_agent_id_t where m_ptr_as_id will hold a string representation of agent's this pointer.

If the name is specified, then agent_t::m_agent_name will contain a copy of name inside, and agent_t::so_agent_name() will return named_agent_id_t that references this name.

So if the name is not used the space penalty will be just sizeof(std::unique_ptr<char[]>) (8 bytes for 64-bit platform).

from sobjectizer.

eao197 avatar eao197 commented on June 2, 2024

It's a part of v.5.8.2 release.

from sobjectizer.

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.